Subscribe - It's FREE!!

Stay Connected Here

Stay Updated With Us Here



Google

Redirect() vs RedirectPermanent in ASP.NET MVC- Understand temporary and permanent redirection types.


Share with WhatsApp


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.



If you enjoyed this post take 5 seconds to share it! Be Socialable. :-)

Share with WhatsApp

Posts To Read Next

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.


Top 10 Visual Studio things which can boost developers coding speed

Visual Studio 2012 provides some coding features by which you can code faster if use them properly. This post will cover top 10 things among them to boost your development speed.


Visual Studio Code - Lighweight but powerful source code editor available for Windows, OS X and Linux

Visual Studio Code is a lightweight but powerful source code editor which runs on your desktop and is available for Windows, OS X and Linux. It comes with built-in support for JavaScript, TypeScript and Node.js and has a rich ecosystem of extensions for other languages (C++, C#, Python, PHP) and runtimes.


Your opinion is valuable for us! Comments, suggetions are welcome.


Submit your Email Id to stay updated with us and get notified with our new posts. It's FREE!
Vu 32'' TV Vu 24'' TV
We know this popup is disturbing you!
But We would greatly appreciate if you share us with your friends below!

It will not take more than 2 seconds but will motivate us greatly to write more,share more!

x