ASP.NET Routing - Do Custom Routes FULLY SKIP Everything in Global.asax?

I have a simple ASP.NET 3.5 SP1 Web Forms application ... I added the System.Web.Routing library and I made a simple route that returns the standard ASP.NET page as "IHttpHandler".

Everything is fine ... except that HttpContext.Current.User is null ???

So, I did a little more digging (I set breakpoints in all the events in the Global.asax file). Usually these breakpoints fall (when I go to the standard ".aspx" page):

  • Application_BeginRequest
  • Application_AuthenticateRequest
  • Application_EndRequest

But when using ASP.NET routing ... none of these events fires. Did I miss something?

+2
webforms routing
Dec 30 '09 at 13:20
source share
4 answers

Assuming you are using IIS6, an alternative is to define a wild card extension handler. Adding this simple catch-all mapping to IIS6 will allow it to handle your requests without extension. By default, the .NET installer maps ".aspx" to aspnet_isapi.dll - why the .aspx extension works. To map requests without an extension to the APS.NET engine, you must tell IIS about each request.

Here is a short article that explains the process:

http://haacked.com/archive/2008/11/26/asp.net-mvc-on-iis-6-walkthrough.aspx

Hope this helps and reduces the lame factor of your urls. :)

-Todd

+7
Jan 12 '09 at 19:36
source share

Found a fancy and crazy answer :)

If you do not add ".aspx" to the end of your route, nothing happens in Global.asax, that is, you do not get any BeginRequest, AuthenticateRequest, EndRequest, etc. Also, t get a SessionState or something else.

So, the “fix” was just for me to change my route:

RouteTable.Routes.Add("Blah", new Route("Blah/{reportName}", new MyHandler()); 

:

 RouteTable.Routes.Add("Blah", new Route("Blah/{reportName}.aspx", new MyHandler()); 

How completely lame :): but this fix doesn't matter!

+2
Dec 30 '09 at 13:51
source share

When you speak

“If you do not add“ .aspx ”to the end of your route, nothing works in Global.asax, that is, you won’t get any BeginRequest, AuthenticateRequest, EndRequest, etc. Besides, you don’t get a SessionState or anything yet.

Will IIS log such requests in log files or are they just anonymous? what about application and viewstate variables?

Sorry, I haven't tested it yet, but just asked if you can already know?

0
Apr 17 '09 at 9:50
source share

I checked the application variable and Viewstate, these two obviously work. Not sure about server logs: S

0
Apr 17 '09 at 10:56
source share



All Articles