I have a shared view called NotAuthorised in the folder ‘Views/Shared’. I want to redirect the users to this view when they are not authorised to see the page.
Initially, this view was in a folder called Account. But I moved it into the Shared folder as I am not using the Account anymore. I have deleted the Account folder.
I used the following code to redirect:
public ActionResult NotAuthorised()
{
return RedirectToAction("NotAuthorised", "Account");
}
Now that I removed the Account folder, I’m trying to use
public ActionResult NotAuthorised()
{
return RedirectToAction("NotAuthorised", "Shared");
}
I am completely wrong by giving the folder name shared in the last line.
Could anyone tell me, what I am doing wrong?
Thank you
You can’t redirect to a
View, only to anActionof aController. You have to specify an controller action for your redirect and there you can render your shared view.and later redirect to this new action from within any other action method:
But you may not need this additional
Controller. You could simply render the sharedView