c# - 如何从 url 中删除 '.aspx' 扩展名

标签 c# asp.net

<分区>

如何在 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/

相关文章:

c# - 每次调用 Equals 都会返回 false,即使值相同 (C#)

c# - 以CSV格式导出到EXCEL时用逗号(,)分隔字符串c#

c# - iTextSharp : The process cannot access the file. 文件流似乎已关闭

jquery - 我如何获得标签的值

c# - 如何访问 html 表 td 值以进行代码隐藏?

c# - 如何选择列表的前 3 项 <>

c# - 使用远程 sql server 进行批量插入时出现异常

c# multithreading 方法名称预期

c# - <链接 rel ="Stylesheet"类型 ="text/css"href ="<% ResolveUrl("~/Css/test.css") %>"/>

asp.net - 文件上传 : ApiController