简体   繁体   中英

How to do forward URl Rewriting using ASP.NET website

I want to know how to do forward URL rewriting in ASP.NET web applications. For example creating sub domain type of URL without creating Sub Domain at IIS .

For example if user types

http://subdomain.example.com

I would get this after doing my forward URL rewriting

http://www.example.com/name=subdomain

Is there any way to do this when I have an ASP.NET website?

Create one CS Class let say "MainClassName" and write code as below in cs file

public class MainClassName
 {
   public static void SubClassName(RouteCollection routes)
       {
        routes.MapPageRoute(
         "RouteName",      // Route name
         "{name}-{some extentions}.aspx",      // Route URL (subdomain-example.aspx)
         "~/home.aspx",// Web page to handle route
        );
       }
  }

please write below code in globle.asmx page

void Application_Start(object sender, EventArgs e)
{
    MainClassName.SubClassName(RouteTable.Routes);
}

when you will use subdomain-example.aspx this url then, it will redirect to home.aspx?name=SubDomain

Create an ASP.NET web site and deploy it as subdomain.example.com

This site has one page, default.asp, which contains the single line <% Response.Redirect("www.example.com/name=subdomain") %>

Write another website and deploy it at www.example.com

It will work without complicated and error-prone URL rewriting logic

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