Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MVC Authentication bypass for a single controller/action

Tags:

asp.net-mvc

I am using MVC with forms authentication and i need authentication bypass for one of my controllers, is it possible to bypass authentication for Cotroller(s)/Action(s). I have been through ASP.NET MVC Forms authentication and unauthenticated controller actions , but i dont want to restrict any action for a user/role , i want to allow it anonymously.

Can anyone help in this regard.

like image 926
Furqan Hameedi Avatar asked Sep 20 '10 11:09

Furqan Hameedi


2 Answers

The location tag solution posted on the page you linked to actually does work for MVC. The authorization controls around that kick in before the MVC framework has a chance to handle the request:

<configuration>
  <location path="~/MyAnonymousController">
    <system.web>
      <authorization>
        <allow users="?"/>
      </authorization>
    </system.web>
  </location>
</configuration>

Also note that you can put web.config files in sub-directories in your app. So for example, you can put your anonymous-access controller in it's own sub-directory and add a web.config in that directory with a location tag to allow anonymous access to everything in that directory: Web.config: Wildcards in location and authorization

like image 146
Shashi Penumarthy Avatar answered Oct 24 '22 19:10

Shashi Penumarthy


Go through the following blog, it worked for me:

http://blog.tomasjansson.com/securing-your-asp-net-mvc-3-application

like image 34
Satpal Singh Avatar answered Oct 24 '22 21:10

Satpal Singh