0
我們的ASP.NET應用程序,並在web.config中設置:IIS 7.5:刪除尾部斜槓不起作用
<rewrite>
<rules>
<rule name="RemoveTrailingSlashRule1" stopProcessing="true">
<match url="(.*)/$" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
</conditions>
<action type="Redirect" redirectType="Permanent" url="{R:1}" />
</rule>
</rules>
</rewrite>
但是,最後的斜線仍然存在。
另外,我試圖用代碼的Global.asax.cs文件:
protected void Application_BeginRequest(Object sender, EventArgs e)
{
if (HttpContext.Current.Request.Url.ToString().Contains("http://concert.local/elki/"))
{
HttpContext.Current.Response.Status = "301 Moved Permanently";
HttpContext.Current.Response.AddHeader("Location", Request.Url.ToString().Replace("http://concert.local/elki/", "http://concert.local/elki"));
}
}
但是,它並沒有正常工作。
具體是「elki」是子文件夾中的項目,他有自己的web.config文件看起來如下:
<configuration>
<system.webServer>
<defaultDocument>
<files>
<add value="Sections.aspx" />
</files>
</defaultDocument>
<httpRedirect enabled="true" destination="/elki" httpResponseStatus="Permanent" />
</system.webServer>
</configuration>
如何使它工作,那就是去掉結尾的斜線?