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?
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.
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.
ojm37
Contributor
2248 Points
832 Posts
Actual file name when in default file
Dec 12, 2011 03:47 PM|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?
TIA,
rstrahl
Contributor
2287 Points
387 Posts
ASPInsiders
MVP
Re: Actual file name when in default file
Dec 15, 2011 04:14 AM|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 ---
West Wind Technologies
Making waves on the Web
www.west-wind.com/weblog
ojm37
Contributor
2248 Points
832 Posts
Re: Actual file name when in default file
Dec 15, 2011 04:17 PM|LINK
Wow! How UN-Efficient this is! Oh well. works well enough...
rstrahl
Contributor
2287 Points
387 Posts
ASPInsiders
MVP
Re: Actual file name when in default file
Dec 15, 2011 06:55 PM|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.
+++ Rick ---
West Wind Technologies
Making waves on the Web
www.west-wind.com/weblog