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".
- [HttpGet]
- public ActionResult GoToPage(string pageName)
- {
- var path = GetPagePath(pageName.Trim());
-
- if (!string.IsNullOrWhiteSpace(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 = "" });
- }
- }
Can someone help on this?