Closed. This question needs to be more focused 。它目前不接受答案。












想改善这个问题吗?更新问题,使其仅通过 editing this post 关注一个问题。

6年前关闭。



Improve this question




如何从 C# 中的页面 URL 中删除扩展名。

例如:questions/ask.aspx
我需要以下格式的 Web 应用程序的 url:
questions/ask

如果有人有想法,请指导我...

最佳答案

如果您使用 Web 表单,则需要在 Global.asax 文件中使用 URL Routing 添加自定义路由器处理程序。
查看此示例:

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/

10-12 12:40
查看更多