我有一个 ASP.NET Web 窗体网站,它使用 .NET 4 路由来处理自定义 URL。
我们组织中的某人决定宣传带有加号的 URL(例如 www.domain.com/this+that),所以现在我不得不修改系统以识别此 URL 并路由它到正确的页面。
这是一个在 IIS7.5 上运行的 .NET 4.0 网站。
我已经研究了如何做到这一点,建议是将以下内容添加到我的 web.config 文件中,我已经这样做了。但我仍然收到 IIS 404 错误消息,而且它甚至没有转到我的自定义 404 错误页面。
<system.webServer>
<security>
<requestFiltering allowDoubleEscaping="true">
</requestFiltering>
</security>
</system.webServer>
知道为什么这不起作用吗?
最佳答案
我只能从个人经验出发,但请尝试以下其中之一:
MVC:
[ActionName("this+that")]
public ActionResult ThisThat()
{
return View("ThisThat");
}
web.config 重定向:
<location path="this+that">
<system.webServer>
<httpRedirect enabled="true" destination="www.domain.com/this_that" httpResponseStatus="Permanent" />
</system.webServer>
</location>
更新: 为我而努力。确保 web.config 如下所示:
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.webServer>
<security>
<requestFiltering allowDoubleEscaping="true" />
</security>
</system.webServer>
Global.asax 应该如下所示:
protected void RegisterRoutes(RouteCollection routes)
{
routes.MapPageRoute("Test", "This+That", "~/Test.aspx");
}
关于asp.net - 允许在 ASP.NET 和 IIS7.5 中的路径中使用加号字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18625362/