DotnetSparrow
DotnetSparrow

Reputation: 27996

URL rewriting in asp.net 3.5 withiout IIS

I am working in as asp.net application which is in asp.net 3.5 version. I have a requirement to implement URL rewriting. I have defined 4 pages like

www.abc.com/page1.aspx
www.abc.com/page2.aspx
www.abc.com/page3.aspx
www.abc.com/page4.aspx

I want that when user types www.abc.com/language1 then www.abc.com/page1.aspx open. If user types www.abc.com/language2, then www.abc.com/page2.aspx should open.

Please suggest a solution to it.

Also, as this site is complete and have links sent through email to users ( and some of the links have querystrings) what is best way to redirect users to new urls without querystrings and generate new links using new pattern ?

I have gone through followig techniques:

http://www.iis.net/downloads/microsoft/url-rewrite ( this is with IIS, can i use it with asp.net 3.5 and without IIS ? )

ASP.NET URL Rewriting in very easy way ( it is not tested for security issues)

http://www.hanselman.com/blog/IntroducingASPNETFriendlyUrlsCleanerURLsEasierRoutingAndMobileViewsForASPNETWebForms.aspx ( This require existing links to change ? )

Please suggest

Upvotes: 1

Views: 893

Answers (2)

Priya Gund
Priya Gund

Reputation: 156

You can do this under Application_BeginRequest in Global.asax file, Check If Request comes from specified URL, then Redirect user to another Page, eg : if(Request.Url.ToString().ToLower().Contains("language1.aspx") , then Response.Redirect("Page1.aspx") .

Upvotes: 0

Georgy Grigoryev
Georgy Grigoryev

Reputation: 873

public class Global : System.Web.HttpApplication
{
    void RegisterRoutes(RouteCollection routes)
    {
        routes.Add(new Route("language2", new PageRouteHandler("~/page2.aspx")));
    }

    protected void Application_Start(object sender, EventArgs e)
    {
        RegisterRoutes(RouteTable.Routes);
    }
}

Upvotes: 1

Related Questions