简体   繁体   中英

ASP.NET MVC Deploying an app with forms authentication to IIS 7.5

I'm having difficulty deploying a web app that has forms authentication to IIS 7.5.

I have the following:

  • Forms Authentication
  • Asp.net mvc 2
  • Net Framework 4.0
  • Application Pool is setup for .Net Framework 4.0 and is in Integrated pipeline mode.
  • IIS 7.5 on Windows Server 2008
  • Authentication setup is IIS (ASP.NET Impersonation and Forms Authentication set to ENABLED. The rest set to DISABLED). Inside the settings for Forms authentication the login URL is correct. The cookie settings is (Mode: Use device profile, Name: .ASPXAUTH, Protection Mode: Encryption and validation, Requires SSL: not checked)

Web.Config:

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

I get the following error when running "Manage Application-->Browse" inside IIS Manager.


HTTP Error 401.2 - Unauthorized

You are not authorized to view this page due to invalid authentication headers.

I get the following error when trying to run the deployed app on my local machine:


401 - Unauthorized: Access is denied due to invalid credentials.

You do not have permission to view this directory or page using the credentials that you supplied.

Any ideas on what is going wrong? It works find when run from VS.

If you have a path leading to an eventual [Authorize] attribute, that will cause this - removing the RenderAction or allowing that action to render without [Authorize] fixes it.

In my case, I call Html.RenderAction("Heading") in _Layout.cshtml (renders a "Please log in" or "Welcome back, Ryan"). My Heading actionresult had an AuthorizeAttribute set on it. I removed the AuthorizeAttribute on Heading, and it was resolved.

I'm running the same setup as what you've shown and it works for me. Check to make sure your logon action does not require authorization.

I got this to work by setting the "Anonymous Authentication" to enabled.

Update: Setting it to Anonymous Authetication has causes other problems. I need to keep this disabled.

Any ideas?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM