1

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

2 Answers 2

1
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);
    }
}
Sign up to request clarification or add additional context in comments.

5 Comments

Can I make language2 dynamic so that It can be picked from database and still uses page2.aspx ?
Yes, you can. You can use anything strings like that: RouteTable.Routes.Add(new Route(mymodel.customstring, new PageRouteHandler("~/myphysicalpath.aspx")));
I see it is working in web forms but my images are not shown. I tried to add routes.Ignore("img/{*pathInfo}"); and routes.Add(new Route("img/{*pathInfo}", new StopRoutingHandler())); but still images are not shown.
does this work in 3.5? as per my information this will work in 4.0 and above only! Please correct if i am wrong..! I have tried this in 3.5 framework but it wont allow..!
Did you include UrlRoutingModule module in your web.config file? You can read at MSDN that it's working in .net 3.5.
0

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") .

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.