C# Ho访问不带页面扩展名的页面。aspx
我用c#asp.net托管了一个网站 如何在没有扩展名.aspx的情况下访问页面,如下所示:C# Ho访问不带页面扩展名的页面。aspx,c#,asp.net,C#,Asp.net,我用c#asp.net托管了一个网站 如何在没有扩展名.aspx的情况下访问页面,如下所示: 当我们打开不带扩展名的链接时,它会重定向到一个404错误页面添加到您的项目文件Global.asax。您只需要像这样添加路由 protected void Application_Start(object sender, EventArgs e) { RouteTable.Routes.MapPageRoute("sample", "sample", "~/sites/sample.aspx")
当我们打开不带扩展名的链接时,它会重定向到一个404错误页面添加到您的项目文件
Global.asax
。您只需要像这样添加路由
protected void Application_Start(object sender, EventArgs e)
{
RouteTable.Routes.MapPageRoute("sample", "sample", "~/sites/sample.aspx");
}
使用和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>
重复问题,请参阅以获取参考AP.NET MVC web应用程序不显示.aspx
后缀。对于新的应用程序,您可能应该使用MVC而不是Web表单projects@R.jauch不是重复,ASP.NET自2010年以来发生了很大变化。甚至Web表单现在也有路由。不再需要重写