简体   繁体   English

ASP.NET 友好 URL 和 default.aspx

[英]ASP.NET Friendly URLs and default.aspx

I've implemented Friendly URLs in a Webform project but it allows a user to go to either the root of the website or /default.我已经在 Webform 项目中实现了友好 URL,但它允许用户转到网站的根目录或 /default。 I really want to get rid of the /default option by having it always just route to the root.我真的想通过让它始终只路由到根来摆脱 /default 选项。 I've tried using我试过使用

routes.MapPageRoute("", "Default", "~/")

but that doesn't seem to effect anything.但这似乎没有任何影响。

Anyone now the proper way to accomplish this?现在有人有正确的方法来完成这个吗?

The easiest way to achieve this will be through IIS not in code.实现这一点的最简单方法是通过 IIS 而不是代码。 It will create a 301 redirect from requests to default.aspx to the root.它将创建一个从请求到 default.aspx 到根的 301 重定向。

<system.webServer>
<rewrite>
  <rules>
    <rule name="default page" stopProcessing="true">
      <match url="^default\.aspx$" />
      <action type="Redirect" url="{R:0}" redirectType="Permanent" />
    </rule>
  </rules>
</rewrite>

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

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