locked
Cannot get my user to login but no error messages produced? RRS feed

  • Question

  • User-270965226 posted

    I have been trying to get my user to login successfully but I cannot seem to login in the user successfully. I get no error messages that the user failed to login when I go to Login.aspx (Default visual studio 2013 web forms website template). I am thinking this is a cookie issue. I have two web.config files in the application: one in my account folder and a application wide web.config.  Here's my user creation code (if needed):

     Protected Sub UserManage_CreatingUser(sender As Object, e As LoginCancelEventArgs) Handles UserManage.CreatingUser
            Dim manager As UserManager = New UserManager
            Dim chkRequireEmail As System.Web.UI.WebControls.CheckBox = UserManage.CreateUserStep.ContentTemplateContainer.FindControl("chkRequireEmail")
            Dim emailver As ApplicationUser = manager.FindByEmail(UserManage.Email)
            If chkRequireEmail.Checked And emailver Is Nothing Then
                Dim user = New ApplicationUser() With {.UserName = UserManage.UserName, .Email = UserManage.Email}
                Dim result As IdentityResult = manager.Create(user, UserManage.Password)
                Dim emailconfirmtoken As String
                '   Dim muser As MembershipUser = Membership.CreateUser(user.UserName, UserManage.Password, user.Email)
                Dim provider As New Microsoft.Owin.Security.DataProtection.DpapiDataProtectionProvider("mainwebsite")
                manager.UserTokenProvider = New Microsoft.AspNet.Identity.Owin.DataProtectorTokenProvider(Of ApplicationUser)(provider.Create("ConfirmEmail"))
                emailconfirmtoken = manager.GenerateEmailConfirmationToken(user.Id)
                manager.ConfirmEmail(user.Id, emailconfirmtoken)
                Dim newuser As MembershipUser
                Dim result2 As MembershipCreateStatus
                newuser = Membership.CreateUser(user.UserName, UserManage.Password, UserManage.Email, UserManage.Question, UserManage.Answer, True, result2)
              
    
                If result.Succeeded Then
                    'go to next step in wizard
                    If Membership.ValidateUser(user.Id, UserManage.Password) Then
                        MsgBox("user created correctly!")
                    End If
    
                Else
                    '.Text = result.Errors.FirstOrDefault()
                End If
            End If
        End Sub

    I have a web.config file in Account folder:

    <?xml version="1.0"?>
    <configuration>
    
      <location path="Manage.aspx">
        <system.web>
          <authorization>
              <allow users="*" />
              <deny users ="?" />
          </authorization>
        </system.web>
      </location>
      
      <location path="EventAdmin.aspx">
        <system.web>
          <authorization>
            <allow roles="Pastors" />
            <deny users ="?" />
          </authorization>
        </system.web>
      </location>
      
      <location path="~/Account">
        <system.webServer>
          <directoryBrowse enabled="false"/>
        </system.webServer>
      </location>
    </configuration>

    The machine wide web.config:

    <?xml version="1.0"?>
    <!--
      For more information on how to configure your ASP.NET application, please visit
      http://go.microsoft.com/fwlink/?LinkId=169433
      -->
    <configuration>
      <configSections>
        <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
        <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false"/>
      </configSections>
      <connectionStrings>
        <add name="DefaultConnection" connectionString="Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\Security.mdf;Integrated Security=True" providerName="System.Data.SqlClient"/>
        <add name="ConnectionString" connectionString="Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\ChurchInfo.mdf;Integrated Security=True;" providerName="System.Data.SqlClient"/>
      </connectionStrings>
      <system.net>
        <mailSettings>
          <smtp from="blah@gmail.com">
            <network host="smtp.google.com" port="25" userName="*****@gmail.com" password="" defaultCredentials="true"/>
          </smtp>
        </mailSettings>
      </system.net>
      <!--
        For a description of web.config changes see http://go.microsoft.com/fwlink/?LinkId=235367.
    
        The following attributes can be set on the <httpRuntime> tag.
          <system.Web>
            <httpRuntime targetFramework="4.5.1" />
          </system.Web>
      -->
      <system.web>
        <authentication mode="Forms"/>
        <compilation debug="true" targetFramework="4.5.1"/>
        <httpRuntime targetFramework="4.5"/>
        <pages>
          <namespaces>
            <add namespace="System.Web.Optimization"/>
            <add namespace="Microsoft.AspNet.Identity"/>
          </namespaces>
          <controls>
            <add assembly="Microsoft.AspNet.Web.Optimization.WebForms" namespace="Microsoft.AspNet.Web.Optimization.WebForms" tagPrefix="webopt"/>
          </controls>
        </pages>
        <membership defaultProvider="SqlMembershipProvider">
          <providers>
            <clear/>
            <add name="SqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="DefaultConnection" applicationName="mainwebsite" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="true" passwordFormat="Hashed"/>
          </providers>
        </membership>
        <profile defaultProvider="DefaultProfileProvider">
          <providers>
            <add name="DefaultProfileProvider" type="System.Web.Providers.DefaultProfileProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="DefaultConnection" applicationName="mainwebsite"/>
          </providers>
        </profile>
        <roleManager defaultProvider="SqlProvider" enabled="true" cacheRolesInCookie="true" cookieName=".ASPROLES" cookieTimeout="30" cookiePath="/" cookieRequireSSL="false" cookieSlidingExpiration="true" cookieProtection="All">
          <providers>
            <add name="SqlProvider" type="System.Web.Security.SqlRoleProvider" connectionStringName="DefaultConnection" applicationName="mainwebsite"/>
          </providers>
        </roleManager>
        <!--
                If you are deploying to a cloud environment that has multiple web server instances,
                you should change session state mode from "InProc" to "Custom". In addition,
                change the connection string named "DefaultConnection" to connect to an instance
                of SQL Server (including SQL Azure and SQL  Compact) instead of to SQL Server Express.
          -->
        <sessionState mode="InProc" customProvider="DefaultSessionProvider" cookieless="AutoDetect">
          <providers>
            <add name="DefaultSessionProvider" type="System.Web.Providers.DefaultSessionStateProvider, System.Web.Providers, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="DefaultConnection"/>
          </providers>
        </sessionState>
      </system.web>
      <system.webServer>
        <modules>
          <remove name="FormsAuthentication"/>
        </modules>
      </system.webServer>
      <runtime>
        <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
          <dependentAssembly>
            <assemblyIdentity name="Newtonsoft.Json" culture="neutral" publicKeyToken="30ad4fe6b2a6aeed"/>
            <bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0"/>
          </dependentAssembly>
          <dependentAssembly>
            <assemblyIdentity name="WebGrease" culture="neutral" publicKeyToken="31bf3856ad364e35"/>
            <bindingRedirect oldVersion="0.0.0.0-1.5.2.14234" newVersion="1.5.2.14234"/>
          </dependentAssembly>
          <dependentAssembly>
            <assemblyIdentity name="EntityFramework" publicKeyToken="b77a5c561934e089"/>
            <bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0"/>
          </dependentAssembly>
          <dependentAssembly>
            <assemblyIdentity name="Microsoft.Owin" culture="neutral" publicKeyToken="31bf3856ad364e35"/>
            <bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0"/>
          </dependentAssembly>
          <dependentAssembly>
            <assemblyIdentity name="Microsoft.Owin.Security.OAuth" culture="neutral" publicKeyToken="31bf3856ad364e35"/>
            <bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0"/>
          </dependentAssembly>
          <dependentAssembly>
            <assemblyIdentity name="Microsoft.Owin.Security.Cookies" culture="neutral" publicKeyToken="31bf3856ad364e35"/>
            <bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0"/>
          </dependentAssembly>
          <dependentAssembly>
            <assemblyIdentity name="Microsoft.Owin.Security" culture="neutral" publicKeyToken="31bf3856ad364e35"/>
            <bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0"/>
          </dependentAssembly>
        </assemblyBinding>
      </runtime>
      <entityFramework>
        <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
          <parameters>
            <parameter value="mssqllocaldb"/>
          </parameters>
        </defaultConnectionFactory>
        <providers>
          <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer"/>
        </providers>
      </entityFramework>
    </configuration>

    Lastly, here's my login code:

    Imports Microsoft.AspNet.Identity
    Imports Microsoft.AspNet.Identity.EntityFramework
    Imports Microsoft.AspNet.Identity.Owin
    Imports System.Linq
    Imports System.Web
    Imports System.Web.UI
    Imports Microsoft.Owin.Security
    
    Public Partial Class Account_Login
        Inherits Page
        Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
            RegisterHyperLink.NavigateUrl = "Register"
            OpenAuthLogin.ReturnUrl = Request.QueryString("ReturnUrl")
            Dim returnUrl = HttpUtility.UrlEncode(Request.QueryString("ReturnUrl"))
            If Not [String].IsNullOrEmpty(returnUrl) Then
                RegisterHyperLink.NavigateUrl += "?ReturnUrl=" & returnUrl
            End If
        End Sub
    
        Protected Sub LogIn(sender As Object, e As EventArgs)
            If IsValid Then
                ' Validate the user password
                Dim manager = New UserManager()
                Dim user As ApplicationUser = manager.Find(Login1.UserName, Login1.Password)
                If user IsNot Nothing Then
                    IdentityHelper.SignIn(manager, user, Login1.RememberMeSet)
                    IdentityHelper.RedirectToReturnUrl(Request.QueryString("ReturnUrl"), Response)
                Else
                    FailureText.Text = "Invalid username or password."
                    ErrorMessage.Visible = True
                End If
            End If
        End Sub
    End Class

    Am I doing something wrong?

    Thursday, March 19, 2015 11:53 AM

Answers

  • User-270965226 posted

    Nevermind, this was a very easy solve. I created a new webforms website project and copied the code for the login aspx page back and it worked! I will move this code into login control code to limit the amount of code in the *.aspx file.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, March 19, 2015 12:12 PM