简体   繁体   中英

How to rewrite an url in global.asax.cs without using the rewrite rule in web.config?

Need your expert help. I am trying to rewrite the url of a page in global.asax.cs page without the use of rewrite rule.The process of rewriting the url occurs but the page is not getting displayed.I am getting the following error occurs "HTTP Error 404.0 - Not Found The resource you are looking for has been removed, had its name changed, or is temporarily unavailable."

You can use System.Web.Routing to do URL rewrite from Global.asax like,

protected void Application_Start(object sender, EventArgs e)
{
    RegisterRoutes(RouteTable.Routes);
}
public static void RegisterRoutes(RouteCollection routecollection)
{
    routecollection.MapPageRoute("Login", "Login", "~/Login.aspx");
}

You can refer this link .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM