<p>I set up a website to use SqlMembershipProvider as written on <a href="http://msdn.microsoft.com/en-us/library/ms998347.aspx" rel="nofollow noreferrer">this page</a>.</p>

<p>I followed every step. I have the database, I modified the Web.config to use this provider, with the correct connection string, and the authentication mode is set to Forms. Created some users to test with.</p>

<p>I created a Login.aspx and put the Login control on it. Everything works fine until the point that a user can log in. </p>

<p>I call Default.aspx, it gets redirected to Login.aspx, I enter the user and the correct password. No error message, nothing seems to be wrong, but I see again the Login form, to enter the user's login information. However if I check the cookies in the browser, I can see that the cookie with the specified name exists.</p>

<p>I already tried to handle the events by myself and check, what is happening in them, but no success.</p>

<p>I'm using VS2008, Website in filesystem, SQL Express 2005 to store aspnetdb, no role management, tested with K-Meleon, IE7.0 and Chrome.</p>

<p>Any ideas?</p>

<p><strong>Resolution:</strong> After some mailing with Rob we have the ideal solution, which is now the accepted answer.</p>

[{'answer_id': 62036, 'author': 'Jon Limjap', 'author_id': 372, 'author_profile': 'https://Stackoverflow.com/users/372', 'pm_score': 1, 'selected': False, 'text': '<p>What is the role of the username you are logging in with? Have you permitted this role to access Default.aspx?</p>\n\n<p>I experienced this once (a long time ago) and went "doh!" when I realized that not even admin roles can access the main folder!</p>\n'}, {'answer_id': 62039, 'author': 'Rob Cooper', 'author_id': 832, 'author_profile': 'https://Stackoverflow.com/users/832', 'pm_score': 0, 'selected': False, 'text': '<p>Have you checked that the redirect path is being sent to the login form? Off my head I think it is <strong>ReturnURL</strong>?</p>\n'}, {'answer_id': 62047, 'author': 'Biri', 'author_id': 968, 'author_profile': 'https://Stackoverflow.com/users/968', 'pm_score': 0, 'selected': False, 'text': "<p>@Jon: I'm not using roles yet. If I check the Web Admin Tool, it says: Roles are not enabled  .</p>\n\n<p>@Rob: Yes, it is there.</p>\n\n<p>I also checked the events in order: LoggingIn, Authenticate, LoggedIn, so it is following the correct path, but no redirect and it does not see that it was authenticated.</p>\n"}, {'answer_id': 62050, 'author': 'Leo Moore', 'author_id': 6336, 'author_profile': 'https://Stackoverflow.com/users/6336', 'pm_score': 2, 'selected': False, 'text': '<p>You normally have a initial folder with the generally accessable forms and a seperate folder with all the login protected items. In the initial folder you have a webconfig with:</p>\n\n<pre><code>   &lt;!--Deny all users --&gt;\n   &lt;authorization&gt;\n     &lt;deny users="*" /&gt;\n   &lt;/authorization&gt;\n</code></pre>\n\n<p>In the other folder you can put a seperate webconfig with settings like:</p>\n\n<pre><code>   &lt;!--Deny all users unless autherticated --&gt;\n   &lt;authorization&gt;\n     &lt;deny users="?" /&gt;\n   &lt;/authorization&gt;\n</code></pre>\n\n<p>If you want to further refine it you can allow access to a particular role only.</p>\n\n<pre><code>&lt;configuration&gt;\n   &lt;system.web&gt;\n      &lt;authorization&gt;\n         &lt;allow roles="Admins"/&gt;\n         &lt;deny users="*"/&gt;\n      &lt;/authorization&gt;\n   &lt;/system.web&gt;\n&lt;/configuration&gt;\n</code></pre>\n\n<p>This will deny access to anyone who does not have a role of admin, which they can only get if they are logged in sucessfully.</p>\n\n<p>If you want some good background I recommend the DNR TV episode with Miguel Castro on  <a href="http://www.dnrtv.com/default.aspx?showNum=20" rel="nofollow noreferrer">ASP.NET Membership</a></p>\n'}, {'answer_id': 62058, 'author': 'Rik', 'author_id': 5409, 'author_profile': 'https://Stackoverflow.com/users/5409', 'pm_score': 1, 'selected': False, 'text': '<p>I ran into a similar problem a while ago, and I remember it was solved by <em>not naming the login page "login.aspx"</em>. Just naming it something else (userLogin.aspx, for example) solved it for me.</p>\n'}, {'answer_id': 62084, 'author': 'Chris Driver', 'author_id': 5217, 'author_profile': 'https://Stackoverflow.com/users/5217', 'pm_score': 0, 'selected': False, 'text': '<p>Do you have <code>requireSSL="true"</code> in your web.config?\nI had similar symptoms to you. If you set requireSSL to true, there are some <a href="http://msdn.microsoft.com/en-us/library/ms998347.aspx#paght000022_additionalconsiderations" rel="nofollow noreferrer">additional considerations</a>.</p>\n'}, {'answer_id': 62092, 'author': 'Rob Cooper', 'author_id': 832, 'author_profile': 'https://Stackoverflow.com/users/832', 'pm_score': 3, 'selected': False, 'text': '<h2>RE: The Accepted Answer</h2>\n<p>I <strong>do not</strong> like the hack given.</p>\n<p>I have a site that uses a login form called &quot;<em>login.aspx</em>&quot; and all works <strong>fine</strong>. I think we should actually find the answer rather than hack. Since all the [presumably] tested sites work. <strong>Do you not think we should actually use StackOverflow to find the ACTUAL problem?</strong> (making it much more useful than anywhere else?)</p>\n<p>In the <strong>LoginCtl_Authenticate</strong> event are you setting the <strong>EventArgs.Authenticated</strong> property to <strong>true</strong>?</p>\n<p>e.g.</p>\n<pre><code>protected void LoginCtl_Authenticate(object sender, AuthenticateEventArgs e)\n{\n   // Check the Credentials against DB\n   bool authed = DAL.Authenticate(user, pass);\n   e.Authenticated = authed;\n}\n</code></pre>\n'}, {'answer_id': 62104, 'author': 'Biri', 'author_id': 968, 'author_profile': 'https://Stackoverflow.com/users/968', 'pm_score': 0, 'selected': False, 'text': '<p>@Rob: You are right from your point of view.</p>\n\n<p>From my point of view it is my test project to check some things. If it is working in any way, that fits to me. I haven\'t found any similair problem on the net, so it can be something else, absolutely not related to ASP.NET.</p>\n\n<p>However I\'m open, so that next time I also can say: aha, I know this!</p>\n\n<p>I started over the project:</p>\n\n<p>Default.aspx: added LoginStatus and LoginName controls</p>\n\n<p>Login.aspx: added Login control and CreateUserWizard control</p>\n\n<p>web.config: added</p>\n\n<pre><code>&lt;authentication mode="Forms"&gt;\n    &lt;forms name="SqlAuthCookie" timeout="10" loginUrl="Login.aspx"/&gt;\n&lt;/authentication&gt;\n&lt;authorization&gt;\n    &lt;deny users="?"/&gt;\n    &lt;allow users="*"/&gt;\n&lt;/authorization&gt;\n&lt;membership defaultProvider="MySqlMembershipProvider"&gt;\n    &lt;providers&gt;\n        &lt;clear/&gt;\n        &lt;add name="MySqlMembershipProvider" connectionStringName="MyLocalSQLServer" applicationName="MyAppName" type="System.Web.Security.SqlMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/&gt;\n    &lt;/providers&gt;\n&lt;/membership&gt;\n</code></pre>\n\n<p>and</p>\n\n<pre><code>&lt;connectionStrings&gt;\n    &lt;add name="MyLocalSQLServer" connectionString="Initial Catalog=aspnetdb;data source=iballanb\\sqlexpress;uid=full;pwd=full;"/&gt;\n&lt;/connectionStrings&gt;\n</code></pre>\n\n<p>Create the database with <code>aspnet_regsql -E -S iballanb\\sqlexpress -A all</code>, created an SQL user called <em>full</em> with password <em>full</em>.</p>\n\n<p>Start the project, I got redirected to Login.aspx, create one user, it is created in database. Entering user data to login form, catching events: LoggingIn, Authenticate, LoggedIn, so I\'m logged in ( I don\'t do anything in these events, I don\'t authenticate myself, I\'m only interested in what is fired and in which order). RedirectURL is correctly pointing to Default.aspx, but has no effect.</p>\n\n<p>This is it so far.</p>\n'}, {'answer_id': 62124, 'author': 'Rob Cooper', 'author_id': 832, 'author_profile': 'https://Stackoverflow.com/users/832', 'pm_score': 0, 'selected': False, 'text': '<p>If you are overriding the events, are you <strong>calling the default implementation?</strong> If you are overriding them to confirm their execution, then the actual code will not be getting executed either, which may be the break in the plumbing..</p>\n'}, {'answer_id': 65670, 'author': 'Rob Cooper', 'author_id': 832, 'author_profile': 'https://Stackoverflow.com/users/832', 'pm_score': 4, 'selected': True, 'text': "<p>I have checked the code over in the files you have sent me (thanks again for sending them through).</p>\n<p><strong>Note: I have not tested this since I have not installed the database etc..</strong></p>\n<p>However, I am pretty sure this is the issue.</p>\n<p>You need to set the <em>MembershipProvider</em> Property for your ASP.NET controls. Making the definitions for them:</p>\n<pre><code>&lt;asp:Login ID=&quot;Login1&quot; runat=&quot;server&quot; \n    MembershipProvider=&quot;MySqlMembershipProvider&quot;&gt;\n    &lt;LayoutTemplate&gt;\n        &lt;!-- template code snipped for brevity --&gt;\n    &lt;/LayoutTemplate&gt;\n&lt;/asp:Login&gt;\n</code></pre>\n<p>And..</p>\n<pre><code>&lt;asp:CreateUserWizard ID=&quot;CreateUserWizard1&quot; runat=&quot;server&quot; \n    MembershipProvider=&quot;MySqlMembershipProvider&quot;&gt;\n        &lt;WizardSteps&gt;\n            &lt;asp:CreateUserWizardStep runat=&quot;server&quot; /&gt;\n            &lt;asp:CompleteWizardStep runat=&quot;server&quot; /&gt;\n        &lt;/WizardSteps&gt;\n    &lt;/asp:CreateUserWizard&gt;\n</code></pre>\n<p>This then binds the controls to the Membership Provider with the given name (which you have specified in the Web.Config.</p>\n<p>Give this a whirl in your solution and let me know how you get on.\nI hope this works for you :)</p>\n<h3>Edit</h3>\n<p>I should also add, I know you shouldn't need to do this as the default provider is set, but I <em>have</em> had problems in the past with this.. I ended up setting them all to manual and all worked fine.</p>\n"}, {'answer_id': 1747578, 'author': 'Daniel Osterhaus', 'author_id': 212728, 'author_profile': 'https://Stackoverflow.com/users/212728', 'pm_score': 1, 'selected': False, 'text': '<p>I just solved my problem of this happening. Check out the applicationName for your membership provider. \n<a href="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" rel="nofollow noreferrer">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</a></p>\n'}, {'answer_id': 17679617, 'author': 'Cabous', 'author_id': 2587849, 'author_profile': 'https://Stackoverflow.com/users/2587849', 'pm_score': 0, 'selected': False, 'text': '<p>Try adding the path element. It must be the same as your virtual site path, for example\nif you test to /localhost/Authentication</p>\n\n<p>path must be = "/Authentication"</p>\n\n<pre><code>&lt;forms loginUrl="Login.aspx" protection="All" timeout="30" name="AuthTestCookie"\npath="/Authentication" requireSSL="false" slidingExpiration="true"\ndefaultUrl="default.aspx" cookieless="UseCookies" enableCrossAppRedirects="false"/&gt;\n</code></pre>\n'}, {'answer_id': 33831438, 'author': 'Zachary Weber', 'author_id': 2171090, 'author_profile': 'https://Stackoverflow.com/users/2171090', 'pm_score': 0, 'selected': False, 'text': '<p>I know this is an old post, but I found an additional answer... For others in the future with this problem, I found that my web.config file somehow had the following added to the bottom (not sure how). Once I commented the <em></em> out, it worked fine :) Even though I had everything above in the file set properly, this one line caused me over an hour of headache...</p>\n\n<pre><code>&lt;system.webServer&gt;\n  &lt;modules&gt;\n    &lt;remove name="FormsAuthentication" /&gt;\n  &lt;/modules&gt;\n&lt;/system.webServer&gt;\n</code></pre>\n'}]
['https://Stackoverflow.com/questions/62013', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/968/']