Last post Dec 15, 2011 02:55 PM by rstrahl
Dec 12, 2011 11:47 AM|ojm37|LINK
Anyone know how, from inside the httpModule (during AuthorizeRequest), to get the ACTUAL file-name when the default file is executing?
For example, when I go to www.site-name.com/index.aspx I can see /index.aspx from either httpContext.Current.Request.FilePath OR httpContext.Current.Reuquest.ServerVariables("URL"). However, when I go to
www.site-name.com/ and the default file is set to /index.aspx (in web.config), both FilePath and ServerVariables return "/". How do I get the actual file being executed?
Dec 15, 2011 12:14 AM|rstrahl|LINK
The behavior for this is pretty weird, but it sort of makes sense. There's a DefaultDocumentModule that handles this, but this module fires very late in the sequence of Http events - basically just before a handler is supposed to execute.
From what I can see what happens is that the request fires through the pipeline twice - once with the original URL that has the / path, then again after the DefaultDocumentModule has kicked in with the default.aspx (or whatever page your default redirected
to). It's not a redirect though - it's internal to IIS but the pipeline is fully reloaded at that point.
You should see default.aspx (or whatever) come through your module on the second pass.
Hope this helps,
+++ Rick ---
Dec 15, 2011 12:17 PM|ojm37|LINK
From what I can see what happens is that the request fires through the pipeline twice
Wow! How UN-Efficient this is! Oh well. works well enough...
Dec 15, 2011 02:55 PM|rstrahl|LINK
Actually it isn't if you consider what's happening. You don't want IIS or ASP.NET to process the / request any earlier than it does because if it did you couldn't handle things like Routing in the ASP.NET framework. The full URL is processed first and only
if no match is found does it apply the default page from the DefaultDocumentModule which makes good sense to me. If it worked any other way there would be lots of issues if you implement any sort of custom routing code (whether it's using ASP.NET's routing
or some custom routing you do in modules).
If you don't like that you can always implement your own handling of this by checking for extensionless URLs and routing them off to the appropriate handler (ie. default.aspx or index.htm or whatever it is you want to access) but the overhead of the extra
pass through the pipeline is very efficient because it simply assignss the same request data and re-runs with the adjusted URL.