0

can anyone please provide me the details how we can implement custom URL rewriting in asp.net

My current url is look like below :

www.domainname.com/News/default.aspx?newstitle=todays latest news

And now I would like to redirect to below url :

www.domainname.com/News/todays-latest-news

Please suggest me how we can achieve the same.

1

3 Answers 3

1

Add this to global.asax

using System.Web.Routing; //top of the page

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

void RegisterRoutes(RouteCollection routes)
{
    routes.MapPageRoute("", "news/{news}", "~/news/default.aspx");
}

And then you can get the news title in default.aspx like below:

protected void Page_Load(object sender, EventArgs e)
{
    if (this.RouteData.Values.Count > 0)
    {
        string newstitle = this.RouteData.Values[0].ToString();
    }
}
Sign up to request clarification or add additional context in comments.

Comments

0

to achieve your task use the concept called asp.net routing , here is the few examples refer for better understanding

http://www.codeproject.com/Articles/77199/URL-Routing-with-ASP-NET-4-0

http://msdn.microsoft.com/en-us/library/cc668201%28v=vs.100%29.aspx

Comments

0

You can use URLRewriter.Net for this purpose. It's very easy to integrate into asp.net project and also it's open source . Add the dll file of urlRewriter.Net into your project and set the rewriting rule in your web.config file. Although be careful when using it with ajax postback pages. In Raw url if you get ajax postback problem .

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.