locked
Actual file name when in default file RRS feed

  • Question

  • User1254222884 posted

    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,

    Monday, December 12, 2011 11:47 AM

Answers

  • User1622957740 posted

    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 ---

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, December 15, 2011 12:14 AM

All replies

  • User1622957740 posted

    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 ---

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, December 15, 2011 12:14 AM
  • User1254222884 posted

    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...

    Thursday, December 15, 2011 12:17 PM
  • User1622957740 posted

    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 ---

    Thursday, December 15, 2011 2:55 PM