- [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?
Abhishek SharmaPosted Jun 21, 2017, 10:08 AM