Moving From Casini to IIS, Login Fails. How come?
Friday 20 October 2006 @ 10:33 am

Moving From Casini to IIS, Login Fails. How come?

ASP.NET 2.0 Membership

A very common question that comes up while using ASP.NET 2.0 Membership is that when moving a web application from the local developer environment with Visual Studio 2005 (VS2005) to IIS is that login no longer works. Almost everytime this happens, it comes down to the application name in the Membership Profile of Web.Config is set to / instead of the actual application name. That is, if you you were to look at your web.config, this is what you would see.

 

  133  <roleManager enabled=true/>

  134     <membership>

  135       <providers>

  136         <remove name=AspNetSqlMembershipProvider/>

  137         <add name=AspNetSqlMembershipProvider

  138             type=

  139             connectionStringName=LocalSqlServer

  140             enablePasswordRetrieval=false

  141             enablePasswordReset=true

  142             requiresQuestionAndAnswer=true

  143             applicationName=/

  144             requiresUniqueEmail=false

  145             minRequiredPasswordLength=1

  146             minRequiredNonalphanumericCharacters=0

  147             passwordFormat=Hashed

  148             maxInvalidPasswordAttempts=5

  149             passwordAttemptWindow=10 p=“”

  150             asswordStrengthRegularExpression=“”/>

  151       </providers>

  152     </membership>

 

Notice that the applicationName is set to just a "/". To make the application work with IIS, you really need to set that to the name of your application. That is, the correct way to specify applicationName is something more like this:

 

  133 <roleManager enabled=true/>

  134     <membership>

  135       <providers>

  136         <remove name=AspNetSqlMembershipProvider/>

  137         <add name=AspNetSqlMembershipProvider

  138             type=

  139             connectionStringName=LocalSqlServer

  140             enablePasswordRetrieval=false

  141             enablePasswordReset=true

  142             requiresQuestionAndAnswer=true

  143             applicationName=/MyCoolApp1

  144             requiresUniqueEmail=false

  145             minRequiredPasswordLength=1

  146             minRequiredNonalphanumericCharacters=0

  147             passwordFormat=Hashed

  148             maxInvalidPasswordAttempts=5

  149             passwordAttemptWindow=10 p=“”

  150             asswordStrengthRegularExpression=“”/>

  151       </providers>

  152     </membership>

This also makes it so that you can share the same membership database across multiple applications.

- Posted in ASP.NET 2.0, Membership  




2 Responses to “Moving From Casini to IIS, Login Fails. How come?”

  1. Administrator Windows XP Internet Explorer 7.0 Says:

    Scott Guthrie has a more advanced discussion on this at the following URL:

    http://weblogs.asp.net/scottgu/archive/2006/04/22/Always-set-the-_2200_applicationName_2200_-property-when-configuring-ASP.NET-2.0-Membership-and-other-Providers.aspx

  2. Pete Windows XP Internet Explorer 7.0 Says:

    Hi,

    This problems seems similar to what I am having. Consider a simple application that has membership, roles, a Login control and set in web config.

    Logging in works fine in debug but after ‘Publish Web Site’ to the same computer, different virtual directory, login fails.

    I tried this code and I tried
    [assembly: ApplicationName(”Calculator”)]

    Neither one fixed the problem. Would you have any advice?

    (FYI: the security code thing did not work in firefox)

Leave a Reply