如何从网址中删除".aspx"扩展名 [英] How do i remove the '.aspx' extension from url

查看:75
本文介绍了如何从网址中删除".aspx"扩展名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从c#中的页面URL中删除扩展名.

How do i remove extensions from page URL in c#.

例如: questions/ask.aspx

我希望我的Web应用程序的网址采用以下格式:

I want the url of my web application in following format:

questions/ask

如果有人有什么主意,请指导我...

If any one have a idea then pleas guide me...

推荐答案

如果使用的是Web表单,则需要使用

If you are using web forms you need to add a custom router handler using URL Routing in the Global.asax file. Check out this sample:

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);
    } 
}   

这篇关于如何从网址中删除".aspx"扩展名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆