Click here to Skip to main content
15,888,251 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,, all
I want to capture the error code: 401 (user not authorized and i want to send the user to a particular View)...

please review my code and suggest me..thnx in advance...

What I have tried:

This is my Web.config file
XML
<customErrors mode="On">
  <error statusCode="401" redirect="~/Home/SecureMethod"/>

This is my Action Method, i've labeled it with [Authorize] filter
C#
[Authorize]
public ActionResult SecureMethod()
{
  return View();
}

This is my View

Razor
@{
  ViewBag.Title = "SecureMethod";
}
<h2>You are not authorized to view this page...please contact admin!!</h2>
Posted
Updated 12-Aug-17 21:32pm
v3
Comments
F-ES Sitecore 14-Aug-17 4:25am    
I googled "mvc custom 401" and found a few suggestions for solving this, I advise you do the same and if you still can't get it working update your question detailing what approaches you tried that didn't work.
Rohit Singh 15-Aug-17 7:53am    
okie... thnx

1 solution

You are trying to display an error in case user not authorized to access some resource, but your error page requires authorized user, otherwise it does not display (and probably generates an 401 error)...
Remove [Authorize] from your action...
 
Share this answer
 
Comments
Rohit Singh 15-Aug-17 7:53am    
okiee. thnx

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900