Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Turn off Authentication in MVC using web.config

I have an MVC site, secured using [Authorize] attributes, but have an issue on a production website that uses Single Sign On accross a couple or sites on different servers. I want to rule Authentication out as the cause; is there a way to temporarily turn off the Authentication through web.config so that all or some Controller Actions that have the Authorize Attribute can be accessed without logging in?

EDIT:

I have tried adding the following to web.config:

<authentication mode="None" />

But this causes all actions decorated with Authorize Attribute to render blank pages. Actions without Authorize continue to work though

like image 318
mutex Avatar asked Mar 26 '12 21:03

mutex


3 Answers

is there a way to temporarily turn off the Authentication through web.config so that all or some Controller Actions that have the Authorize Attribute can be accessed without logging in?

No, this is not possible with the default framework. I'm pretty sure the AuthorizeAttribute in MVC source code will attempt to check and see if the user is logged in. Without an authenticated user, access would be denied.

like image 152
Erik Philips Avatar answered Nov 15 '22 21:11

Erik Philips


Use [AllowAnonymous] to allow specific actions in a controller be used by unauthorized users.

like image 43
Luke Avatar answered Nov 15 '22 20:11

Luke


In your Web.config comment out the child:

<authentication mode="Windows" />
<authorization>
  <!--<deny users="?" />-->
</authorization>
like image 28
Cyrus Avatar answered Nov 15 '22 21:11

Cyrus