0

I am working on ASP.net MVC 3 application where I need to display a friendly page to user if he does not have access to the application. I followed lot of articles online but none of them mentions an end to end solution to the problem stated above and as a result I am unable to get this to work.

Any pointers ??

Much thanks.

annantDev
  • 367
  • 4
  • 20

2 Answers2

0

What I do in my apps is create a more "friendly" shared view, then set the Response code to whatever I need. For example, I'll create a shared ErrorPage view, then use Response.StatusCode = 500 to make sure the browser properly registers that it is an error page. Can't tell you how many times I've seen customized Page Not Found pages where they didn't properly set the Status Code to 404, so it returned a 200 status and was indexed by a search engine.

Sam
  • 9,933
  • 12
  • 68
  • 104
0

Do you have an [Authorize] setup on your controllers? Paired with

<authentication mode="Forms">
    <forms loginUrl="~/Account/LogOn" timeout="2880" />
</authentication>

instead of a 401, my users get redirected back to my log in page.

Or you could simply do a RedirectToAction if your authentication fails.

Ron
  • 1,721
  • 1
  • 19
  • 43
  • I do have authorize attribute but I am using basic authentication and not forms authentication. In this case, if a user is not authorized they see the ugly 401 (You are not authorized..) page. – annantDev Dec 28 '11 at 16:50
  • RedirectToAction is no good if you want to return a 401 status code on the url without valid permission – DevDave Sep 02 '13 at 11:03