How to redirect to view from shared folder

1.4k Views Asked by At
HttpContext.Response.Redirect("~/Shared/views/Error.cshtml", true);

This is not working for me

And how to exclude the certain controllers and actions

1

There are 1 best solutions below

2
On

As you can see in documentation, method which you are trying to use require to arguments

public void Redirect(string url, bool endResponse)

and first argument is an url of page where user should be redirected, while you are passing view file path. In asp. mvc path to *cshtml file is not equal to url.

I suggest you to use RedirectToRoute method instead

RedirectToRoute(new RouteValueDictionary 
{
    controller = "Error", 
    action = "Index"
}) 

where your desired view is returned by ErrorController.Index() action.