In this post we are going to see how we can use Response.Redirect(Redirecttion) in asp.net friendly URLs. Before some day I have written a post about ASP.NET Friendly URLs – Cleaner, SEO friendly URLs. On that post one reader ‘Ramesh’ asked me that how we can do redirection with ASP.Net friendly URLs. So this post is in reply to Him.
Uh!! don’t believe me!!. Let’s take a sample example. I am going to use by default template with ASP.NET Friendly URLs. So for this example I have created a ASP.Net button in Default template AboutUs.aspx page. Once the click of that button we are going to use ‘Response.Redirect’ for redirection and redirect this page to Contact Page. Following is a html code for that button.
And following is a code click event handler for click event of above button.
That’s it. You are done.
Right now you are on about us page like following.
Now once you click ‘Click me to redirect’,It will load contact page.
That’s it. Hope you like it. Stay tuned for more!!
How to redirect a page to ASP.Net friendly URLs:
Actually!! there is nothing to learn. It’s very easy You can directly use the ‘Response.Redirect’ with the ASP.Net friendly URLs. The NuGet Package itself takes care of all the things. You just need to write the route name as a parameter in ‘Response.Redirect’ and you are done!!Uh!! don’t believe me!!. Let’s take a sample example. I am going to use by default template with ASP.NET Friendly URLs. So for this example I have created a ASP.Net button in Default template AboutUs.aspx page. Once the click of that button we are going to use ‘Response.Redirect’ for redirection and redirect this page to Contact Page. Following is a html code for that button.
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Click me to redirect" />
And following is a code click event handler for click event of above button.
protected void Button1_Click(object sender, EventArgs e) { Response.Redirect("Contact"); }
That’s it. You are done.
Right now you are on about us page like following.
Now once you click ‘Click me to redirect’,It will load contact page.
That’s it. Hope you like it. Stay tuned for more!!
How do you redirect with querystrings?
ReplyDeleteI mean how do you redirect to the ontact page and supply querystring
this way.....if we have a page named-product.aspx then--
ReplyDeleteResponse.Redirect(www.example.com/product?category=1);
You can write Response.Redirect("www.example.com/category/1")
Delete