[英]How to differentiate between / (the root) and /default.aspx in ASP.NET
Request.RawUrl always returns the /default.aspx variant. Request.RawUrl始终返回/default.aspx变体。 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.
IIS 7上的环境是.NET 3.5SP1。
I actually had to combat this same problem when designing my URL Rewriter . 在设计我的URL重写器时,我实际上不得不解决同样的问题。 It has to do with the processes that occur before you can even access the URL's.
它与您甚至可以访问URL之前发生的过程有关。 To get around this you have to make sure that in IIS 7 the default page handling is turned off.
要解决此问题,您必须确保在IIS 7中关闭默认页面处理。 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.
因为如果没有默认的页面处理,它将不会经历尝试将其映射到驱动器的额外步骤,因此您将是所请求的确切URL。 But this may or may not be an option depending on if you are using
System.Web.Routing
or not. 但这可能是也可能不是一个选项,具体取决于您是否使用
System.Web.Routing
。
To turn off the default page handling you need to do the following: 要关闭默认页面处理,您需要执行以下操作:
Or you can add the following to your web.config
: 或者您可以将以下内容添加到
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. 执行此操作后,默认文档将不再添加到您的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.
但是要注意,由于这不再是活动的,你不能依赖default.aspx实际映射到你的目录,你必须手动处理它或使用像System.Web.Routing这样的东西来处理这个功能。
To accomplish the same in IIS 6 you need to turn on wildcards: 要在IIS 6中完成相同的操作,您需要打开通配符:
The following instructions apply for IIS 6. 以下说明适用于IIS 6。
NOTE: by the way all the source is available on the site I linked above incase you were curious how I was doing things. 注意:顺便提一下,我在上面链接的网站上提供了所有来源的方式,你很好奇我是怎么做的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.