简体   繁体   中英

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. I really want to get rid of the /default option by having it always just route to the root. 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. It will create a 301 redirect from requests to default.aspx to the root.

<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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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