Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • MaartenVissers 32 posts 150 karma points
    Jan 05, 2022 @ 15:22
    MaartenVissers
    0

    Redirect() vs Response.Redirect()

    What is the difference between

    Redirect()
    

    And

    Response.Redirect()
    

    Thanks in advance!

  • Søren Gregersen 441 posts 1884 karma points MVP 2x c-trib
    Jan 06, 2022 @ 09:23
    Søren Gregersen
    100

    Hi,

    I guess you are taking about https://docs.microsoft.com/en-us/dotnet/api/system.web.httpresponse.redirect?view=netframework-4.8 and https://docs.microsoft.com/en-us/dotnet/api/system.web.mvc.controller.redirect?view=aspnet-mvc-5.2

    The Redirect() creates a result, that is handled in MVC, and based on it, it actually calls the other method, Response.Redirect(), internally.

    The difference between the two, are that the result from the Redirect() call, is handled by MVC, and the Response.Redirect() is handled by ASP.Net.

    Inside a controller, you should return the result from Redirect. Response.Redirect will just add headers to the Response, allowing you to set a redirect, then execute more code before returning the result.

    If you call Response.Redirect inside a controller, and then return another result, you could end up redirecting to the url, when you actually wanted to return some content instead.

    HTH :)

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies