views:

144

answers:

1

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.

+1  A: 

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.

Nick Berardi
I will check this out! Was not aware of your project. I drilled deep into the ASP.NET internals with reflector and found out (very sure about this) that the URL ASP.NET gets (inside IIS7WorkerRequest) is already modified by the native part of IIS before managed code kicks in. I will look into disabling a lot of the default modules in apphost. I just tries disabling default document handling but it changes nothing in cassini webserver. Will try later in IIS.btw IIS + ASP.NET is a giant monster of default behavior. Terrible.
usr
PS: I wonder how you support asp.net forms. Will look at your code.
usr
It wouldn't change anything in Cassini because Cassini follows only the standard `<system.web/>` settings. However Cassini usually is a pretty good judge of what you will see in IIS 7 since it is a pure .NET engine, however it still has some hard codings in there for `default.aspx` and `index.aspx` so that applications `just work`(tm) when running them from Visual Studio for old ASP.NET apps. However you may be able to force it to recognize the URL with out `default.aspx` if you just remove the file from the directory.
Nick Berardi
@usr well there are a couple options for how `<asp:form/>` choose to render URL's, it has been a while since I fooled around with that. In IIS 6 play around with the `<rewriter rebaseClientPath="true|false" />`. I forget if you actually want `true` or `false` to change the URL of the `<asp:form/>`. It is based on this method: http://msdn.microsoft.com/en-us/library/1kz7fdx9(v=VS.90).aspx However in IIS 7 I think it just works, because of `TransferRequest`, but please don't quote me on that.
Nick Berardi