Forums - C# Corner

Forum guidelines
Rohit Singh

Rohit Singh

  • 1.5k
  • 7
  • 460

How to create custom error page for 401 in MVC

Aug 16 2017 4:09 AM
Hi. I've been facing this issue so long and tried almost everything but couldn't get what I want.

I want to display an custom error page for code 401 , if the user is not authorized to view any particular part of my webApplication. Kindly solve my problem.

What I have tried:

This is my web.config file:

<customErrors mode="On">
<error statusCode="404" redirect="~/Error/NotFound"/>
<error statusCode="401" redirect="~/Home/SecureMethod"/>

This is My Controller:

public class HomeController : Controller

public ActionResult SecureMethod()

return View();

public ActionResult NonSecureMethod()
return View();

I have also enabled the Windows Authentication and Anonymous Authentication on IIS Server

Answers (2)