0
votes

I have created 2 asp.net mvc applications that I want to share the same membership database, Site A and B. The problem is the second application (Site B), is prompting me to login again immediately after successfully logging in. There is no error message, it just returns to login. If I put in some incorrect credentials it will say invalid login attempt, so I know its taking the users somehow.

I tried registering a user on the site and the new user appears in my membership database (viewable in Site A), but even after registering a new user through Site B, site B still returns to the login screen after logging in.

Basically this makes the user stuck, because they can never login (just logging in endlessly).

I have the following in both site's webconfig to point them to the same database. The Default Connection string is the same for both sites.

<membership defaultProvider="SqlProvider" userIsOnlineTimeWindow="20">
  <providers>
    <add name="SqlProvider"
      type="System.Web.Security.SqlMembershipProvider"
      connectionStringName="DefaultConnection"
      enablePasswordRetrieval="true"
      enablePasswordReset="false"
      requiresQuestionAndAnswer="true"
      passwordFormat="Encrypted"
      applicationName="MyApplication" />
  </providers>
</membership>

I am placing the authorize attribute in my pages by placing this in the FilterConfig.cs in App_Start

 filters.Add(new System.Web.Mvc.AuthorizeAttribute());

I tried Authorizing by specific user roles that I knew users I logged in with had, but it just ran into the same issue of being returned to the login screen.

I have no idea whats going on. Clearly its logging in but something is getting lost or not recorded properly. Any ideas what I should try to resolve this?

Maybe its related to session cookies?

1

1 Answers

1
votes

Not a lot to go on based on your description. Guessing you are authenticating via forms authentication? In the section of code were you are checking the password, before the redirect to the requested page, are you setting the Authentication Cookie? Something like the following....

FormsAuthentication.SetAuthCookie(username, persistentCookie);