<分区>
如何在 C# 中删除页面 URL 的扩展。
例如:questions/ask.aspx
我想要我的网络应用程序的 url 格式如下:
questions/ask
如果有人有想法,请指导我......
<分区>
如何在 C# 中删除页面 URL 的扩展。
例如:questions/ask.aspx
我想要我的网络应用程序的 url 格式如下:
questions/ask
如果有人有想法,请指导我......
最佳答案
如果您使用的是 Web 表单,则需要使用 URL Routing 添加自定义路由器处理程序在 Global.asax
文件中。
查看此示例:
Global.asax
public class Global : System.Web.HttpApplication
{
//Register your routes, match a custom URL with an .aspx file.
private void RegisterRoutes(RouteCollection routes)
{
routes.MapPageRoute("About", "about", "~/about.aspx");
routes.MapPageRoute("Index", "index", "~/index.aspx");
}
//Init your new route table inside the App_Start event.
protected void Application_Start(object sender, EventArgs e)
{
this.RegisterRoutes(RouteTable.Routes);
}
}
关于c# - 如何从 url 中删除 '.aspx' 扩展名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27792467/