Set endResponse default value to false for Response.Redirect

974 views Asked by At

Recently Im trying convert ASP.NET 2.0 project to MVC 5, where in application there're more than 200 webform are there, where Response.Redirect("URL") is used, which is not working after converting to MVC 5 project, the solution I found is to set endResponse to false for overridden parameter as following

Response.Redirect("URL",false);

now its not easy and feasible to open 200+ files and update this line, so is there any way where we can set this flag as false as a default value or can we override this Response.Redirect method?

or is there any way to find Response.Redirect("URL") with some regular expression and replace all in a single shot?

Any help would be appreciated.

1

There are 1 answers

2
Adam On BEST ANSWER

A regex find and replace would work but my regex isn't great but I have a simpler find and replace.

Create a new function

public void NewRedirect(String url)
{
    Response.Redirect(url, false);
}

Then do a find and replace of

Response.Redirect

to

NewRedirect

This keeps all your redirects in one place and manageable for the future. I do something a little more complex but similar to the above in my apps to manage all redirects. It is very handy in many situations to ensure you control all redirects.

Edit

In answer to your question of is there an override method, the answer is no.

If you look at the .NET source http://referencesource.microsoft.com/#System.Web/HttpResponse.cs,485d70e24a9bc19c

You will see there is no other place other than that value it gets endResponse, hence it has to be set in the parameter during the method call.

The only other option is to override the method in HttpResponse but I seriously don't recommend you do that.