Reputation: 223
I am using MVC 2.0 with forms authentication. I want to allow public access to one controller called "Logout". Currently whenever I browse to it I get bounced to Login.
<authentication mode="Forms">
<forms loginUrl="Login/Login"
protection="All" timeout="30"
name=".ASPXAUTH"
path="/"
requireSSL="false"
slidingExpiration="true"
defaultUrl="Token/Create"
cookieless="UseDeviceProfile"
enableCrossAppRedirects="false" />
</authentication>
<!-- Deny Anonymous users. -->
<authorization>
<deny users="?" />
</authorization>
Upvotes: 3
Views: 6095
Reputation: 16038
As SLaks mentioned, there should be no need for a non-logged-in user to access the Logout action. But, if you want to enable anonymous access to controllers / actions you have to enable it in your Web.Config:
<location path="~/Logout">
<system.web>
<authorization>
<allow users="?" />
</authorization>
</system.web>
</location>
A better approach for a pure MVC app is to use the Authorize
attribute and enable access to all users in the web.config.
Upvotes: 3
Reputation: 1759
you are better off using attributes on your controllers and/or controller actions than specifying authorization in config. [Authorize] for the actions you want limited to authenticated users and then the ones without the attribute are publicly available.
Upvotes: 2