Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove forms authentication on an MVC 4 website

Background

I started an MVC 4, .Net 4.5 website with a view to using Forms authentication, so chose that template. The brief then changed, and I needed to swap to using Windows Authentication instead. This is rolled out onto a Windows Server 2008 box with IIS8.

The problem

I can't for the life on me turn Forms authentication off. After being authenticated through NTLM successfully, MVC tries to take me to a forms login page. I have tried:

  • Changing the web.config to <authentication mode="Windows" >
  • Changing the IIS application to use "Windows Authentication" as oppose to "Forms Authentication" (Anonymous Authentication is of course, off)
  • I have tried commenting out "AuthConfig.RegisterAuth();" and "FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);" in the Application_Start()
  • I've tried setting HttpResponse.SuppressFormsAuthenticationRedirect in the Application_EndRequest.

None of this works. The only horrible fudge that has worked (from a fellow stackoverflow post) was to change the below in the web.config - this has some funky side effects though (bouncing back to Home on navigation when the app shouldn't for instance) :

<authentication mode="Windows" >
  <!--<forms loginUrl="~/Account/Login" timeout="2880" />-->
  <forms loginUrl="~/Home" timeout="2880" />
</authentication>

The question

I feel I am missing some blindingly obvious (probably filter related) change I need to make to disable and remove forms auth from the project. Can anyone suggest the steps I need to take to remove in permanently?

like image 581
MagicalArmchair Avatar asked Mar 27 '26 10:03

MagicalArmchair


1 Answers

ASP.NET MVC3 and Windows Auth on IIS keeps redirecting to /Account/Login

Check whether you have WebMatrix.Data.dll and/or WebMatrix.WebData.dll deployed in the bin directory of your application. If they are there (and you know you don't use them) then try removing them and accessing a page that requires authentication.

I removed references in the project to WebMatrix, deleted them from the local bin and the remote bin, and the unexpected behaviour stopped.

like image 196
MagicalArmchair Avatar answered Apr 01 '26 08:04

MagicalArmchair



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!