Have page come up without the .aspx [duplicate]

2019-06-03 07:58发布

This question already has an answer here:

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.

标签: asp.net url
5条回答
爷的心禁止访问
2楼-- · 2019-06-03 08:42

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

There is a good article here.

查看更多
倾城 Initia
3楼-- · 2019-06-03 08:44

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.

查看更多
三岁会撩人
4楼-- · 2019-06-03 08:53

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

查看更多
Fickle 薄情
5楼-- · 2019-06-03 08:54

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.

查看更多
做自己的国王
6楼-- · 2019-06-03 09:00

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.

查看更多
登录 后发表回答