简体   繁体   English

如何区分ASP.NET中的/(root)和/default.aspx

[英]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: 要关闭默认页面处理,您需要执行以下操作:

  1. Go to your site in IIS 在IIS中转到您的站点
  2. Go to Default Document 转到默认文档
  3. Click Disable in the top right corner. 单击右上角的“ 禁用 ”。

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。

  1. Open IIS and right-click on the website and select 'properties'. 打开IIS并右键单击网站并选择“属性”。
  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. 将可执行文本框设置为aspnet_isapi.dll文件位置。 for .net 2.0, 3.0, 3.5: C:\\Windows\\Microsoft.NET\\Framework\\v2.0.50727\\aspnet_isapi.dll 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. 注意:顺便提一下,我在上面链接的网站上提供了所有来源的方式,你很好奇我是怎么做的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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