- [HttpGet]
- public ActionResult GoToPage(string pageName)
- {
- var path = GetPagePath(pageName.Trim());
- if (!string.IsNullOrWhiteSpace(path))
- {
- // framing the fully qualified path
- path = string.Format("{0}/{1}", ConfigurationFactory.GetConfigurationProvider().GetAppBaseUrl(), path);
- if (!path.ToLower().Contains(".aspx"))
- {
- Response.Redirect(path)); error line
- }
- return Redirect(path);
- }
- else
- {
- return RedirectToAction("AccessDenied", "Error", new { area = "" });
- }
- }
Using Response.Redirect in MVC action
I have an action method in a controller class as shown below and based on a if condition, system should redirect to MVC page. But, Response.Redirect is not working as expected and throws an exception "Cannot redirect after HTTP headers have been set".
Can someone help on this?
1 Answer
Know the answer? Post it. Somebody with the same question will find it here.

Abhishek Sharma52 reputationPosted Jun 21, 2017, 6:08 AM EDT