简体   繁体   中英

How to differentiate between / (the root) and /default.aspx in ASP.NET

Request.RawUrl always returns the /default.aspx variant. I did not find any way at all to differentiate between these urls. Does anybody know how to do that? Environment is .NET 3.5SP1 on IIS 7.

I actually had to combat this same problem when designing my URL Rewriter . It has to do with the processes that occur before you can even access the URL's. To get around this you have to make sure that in IIS 7 the default page handling is turned off. Because if there is no default page handling it is not going to go through the extra step of trying to map it to the drive, so you will be the exact URL requested. But this may or may not be an option depending on if you are using System.Web.Routing or not.

To turn off the default page handling you need to do the following:

  1. Go to your site in IIS
  2. Go to Default Document
  3. Click Disable in the top right corner.

Or you can add the following to your web.config :

<system.webServer>
    <!-- ... other tags here ... -->
    <defaultDocument enabled="false" />
</system.webServer>

After you do this the default document will be no longer added to your URL. However be warned that since this is no longer active you cannot rely on default.aspx actually mapping to your directories, you will have to handle this manually or use something like System.Web.Routing to handle this functionality.

To accomplish the same in IIS 6 you need to turn on wildcards:

The following instructions apply for IIS 6.

  1. Open IIS and right-click on the website and select 'properties'.
  2. Click the 'Configuration' button under Application Settings section
  3. Click the 'Insert...' button to create a new wildcard mapping
  4. Set the executable textbox to aspnet_isapi.dll file location. for .net 2.0, 3.0, 3.5: C:\\Windows\\Microsoft.NET\\Framework\\v2.0.50727\\aspnet_isapi.dll
  5. Make sure the checkbox 'Verify that file exists' is not checked.
  6. Press 'OK' to confirm and close all the windows.

NOTE: by the way all the source is available on the site I linked above incase you were curious how I was doing things.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM