Have page come up without the .aspx [duplicate]

2019-06-03 07:59发布

问题:

This question already has an answer here:

  • ASP.NET web pages without aspx file extension 3 answers

I am using ASP.NET Web Forms.

I have a situation where an ASPX page needs to come up without the .aspx extension.

Following is an example (not real site):

  www.abc.com/firstpage

The page is actually called firstpage.aspx, but I wonder if I could make it work without the .aspx.

The reason why this is important is because an email got sent out with www.abc.com/firstpage, and now I need to figure out how to make it programatically go to www.abc.com/firstpage.aspx.

回答1:

If you are using .net 4.5 you can use Asp.net Friendly URLS: http://aspnetfriendlyurls.codeplex.com/



回答2:

Quick and dirty: create firstpage folder, create index.html file in it. Place this inside:

<html>
  <head>
    <title></title>
    <META http-equiv="refresh" content="0;URL=/firstpage.aspx">
  </head>
  <body>

  </body>
</html>

This will fix your problem without messing around with URL rewrites, etc.



回答3:

If you are using ASP.NET 4.0 or later, then you can use ASP.NET routing in WebForms.

Read Walkthrough: Using ASP.NET Routing in a Web Forms Application.



回答4:

Use a URL rewrite rule (i.e. to rewrite www.abc.com/firstpage to www.abc.com/firstpage.aspx). IIS and third-party rewrite modules (e.g. ones compatible with Apache syntax) can do this.



回答5:

Search for "extensionless URLS" and "URL Rewriting".

There is a good article here.



标签: asp.net url