【问题标题】:Ho to access page without page extension .aspx如何访问没有页面扩展名.aspx的页面
【发布时间】:2016-09-09 10:28:18
【问题描述】:

我使用 c# asp.net 托管了一个网站

The page can be found here

如何访问没有扩展名 .aspx 的页面,如下所示:http://www.dailycashback.in/sample

当我们打开没有扩展名的链接时,它会重定向到 404 错误页面

【问题讨论】:

  • 重复问题,参考this
  • ASP.NET MVC Web 应用程序显示.aspx 后缀。对于新项目,您可能应该使用 MVC 而不是 Web 表单
  • @R.jauch 不是重复的,自 2010 年以来,ASP.NET 发生了很多的变化。现在甚至 Web 窗体也有了路由。不再需要重写

标签: c# asp.net


【解决方案1】:

添加到您的项目文件Global.asax。你只需要像这样添加路由。

protected void Application_Start(object sender, EventArgs e)
{
   RouteTable.Routes.MapPageRoute("sample", "sample", "~/sites/sample.aspx");
}

【讨论】:

    【解决方案2】:

    使用 IIS url rewriter 和 Web.Config。它将允许您请求没有 .aspx 扩展名的每个页面。

      <system.webServer>
        <rewrite>
          <rules>       
            <rule name="no-aspx-extension" stopProcessing="true">
              <match url="^([a-z0-9/]+)$" ignoreCase="true"/>
              <action type="Rewrite" url="{R:1}.aspx"/>
            </rule>
          </rules>
        </rewrite>
      </system.webServer>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-02-04
      • 1970-01-01
      • 2012-09-10
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多