ASP.NET Routing – Do Custom Routes COMPLETELY SKIP Everything in the Global.asax?

I have a simple ASP.NET 3.5 SP1 Web Forms app… I’ve added the System.Web.Routing DLL, and I’ve made a simple route that returns a standard ASP.NET Page as the “IHttpHandler”.

All is good… except that HttpContext.Current.User is null ???

So, I did a little more digging (I put breakpoints in all the events in the Global.asax file). Normally, these breakpoints get hit (when I navigate to a standard “.aspx” page):

  • Application_BeginRequest
  • Application_AuthenticateRequest
  • Application_EndRequest

But, when using ASP.NET Routing… none of those events are firing. Am I missing something?

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

Assuming you’re using IIS6, the alternative is to define a “wild card” extension handler. Adding this simple “catch all” mapping to IIS6 will enable it to process your extensionless requests. By default, the .NET installer maps “.aspx” to the aspnet_isapi.dll- that’s why the .aspx extension works. To map requests with no extension to the APS.NET engine, you must tell IIS to look at every request.

Here’s a quick article that explains the process:

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

Hope that helps and reduces the “lame” factor of your URLs. 🙂

-Todd

Method 2

Found the freakish and bizzare (and stupid) answer 🙂

If you don’t add “.aspx” to the end of your route, nothing fires in the Global.asax, meaning you don’t get any BeginRequest, AuthenticateRequest, EndRequest, etc… Also, you don’t get SessionState or anything.

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

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

to this:

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

How completely lame 🙂 … but it’s a fix none-the-less!

Method 3

When you say

“If you don’t add “.aspx” to the end of your route, nothing fires in the Global.asax, meaning you don’t get any BeginRequest, AuthenticateRequest, EndRequest, etc… Also, you don’t get SessionState or anything.”

Will IIS log such requests in the log files or they are just anonymous? what about Application variables and ViewState?

sorry i haven’t tested it yet, but just asking if you might already know?

Method 4

i have checked application variable and Viewstate, these two are obviously working.. not sure about server logs :S


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x