anuj.rohila94
anuj.rohila94

Reputation: 105

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?

Upvotes: 1

Views: 971

Answers (2)

Jenit
Jenit

Reputation: 1

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

Upvotes: 0

baxter
baxter

Reputation: 42

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

Upvotes: 0

Related Questions