- Posted On 7 August 2014
- In Programming
Hello friend, in this simple post I am going to share information about Redirect() and RedirectPermanent() methods available in ASP.NET and MVC for redirection purpose.
Many developers, especially fresher developers use these methods blindly and mostly they use only Redirect one without understanding the correct use. I decided to share this as one of the junior developer in my team has asked this question to me while I am reviewing his code as he were not aware about its meaning and purpose after explaining him I though better If share the same here for other developers like him.
Let’s start with it.
Redirect and RedirectPermanent both are methods of HttpResponse Class which provides facility to redirect user to another page or URL. There are several other methods too e.g. RedirectToRoute and RedirectToAction with permanent option but the main difference between Redirect and RedirectPermanent will make you clear about the use of these other methods.
Main difference between Redirect and RedirectPermanent is when you use Redirect or any of its overloaded versions to redirect user it sends an HTTP 302 status code to the browser on the other hand RedirectPermanent sends HTTP 301 status code.
If you don’t know what are these code you can check out this link to know more about HTTP 301 and HTTP 302. In simple words HTTP 301 says that redirection is permanent and HTTP 302 says that this redirection is temporary.
Let's understand this by simple example, When you are vacation you keep "out of office" auto response for your email id which has matter like "I am on leave from ... to .. and will be back on ... Please contact with Mr.X at .. So in this case you can say its type of Redirect() i.e HTTP 302 beacuse you are temporarily not available and directing sender to Mr.X on the other hand if someone gets releived from company a mail like Mr.A has been releived with us and here after please contact Mr.B .... so in this case you can say its permanent redirect i.e. HTTP 301 because Mr.A has been releived permanently and all the duties has been moved to Mr.B.
When you use RedirectPermanent then most of the browsers cache this response and redirects user to the new URL always. Better example I will share that for SEO point of view “domain.com” and “www.domain.com” are different URL and it leads to the content duplication if not handled properly so in this case most of the webmasters uses HTTP 301 redirection to tell search engine crawler to consider only one URL.
Hope I have able to explain the difference. Still if you have queries or you have something positive to add this do share in comment section below.
Typewriter - Automatic TypeScript Template generation from C# classes in Visual Studio
Typewriter, an extension for visual studio that generates TypeScript files from C# code files using TypeScript templates. Convert your C# model classes to TypeScript automatically.
Swagger - Powerful Opensource Framework for RESTful API
With a Swagger-enabled API, you get interactive documentation, client SDK generation and discoverability. Swagger Editor allows you to generate code, documentation with ease.
Assembla - Free and private repository to manage your source code online with SVN subversion hosting
With Assembla you can share source code with others online. Free & Private source code repository with SVN Subversion, Git & Perforce Hosting.
Copy changed data in table from one database to another in SQL stored procedure
How to copy or merge changed data in table from one database to another having same schema is the topic of this post.
How to call click or any event only once in jQuery
Know how to execute an click event or any event only once for any element in jQuery. Perform action only once and even not required to unbind event.