aspnet_users表为空,但c#代码表示用户存在

时间:2015-08-01 23:11:24

标签: asp.net .net

我正在使用成员资格,Windows授权和sqlprovider创建一个小的asp.net webforms应用程序。 aspnet表是使用sqlexpress db中的aspnet_regsql.exe工具创建的(与非成员资格内容相同的数据库)。在default.aspx.cs的page_load中,我创建了一个用户: var x = System.Web.Security.Membership.CreateUser(@“larry-gateway \ larry”,“Gilmgilm1”); 我使用以下方法测试其存在:  var me_the_User = System.Web.Security.Membership.GetUser(@“larry-gateway \ larry”); 我得到一个对象 我尝试再次添加它,它失败了 - 重复。 但我看看aspnet_users,它是空的! 所以我必须在不同的数据库中创建它,而不是。\ sqlexpress;我检查连接字符串,除了我想要的之外没有其他字符串。 我搜索类似的问题,他们似乎表明我的问题是我访问不同的数据库。我正在尝试包含我的web.config但是提交检查器似乎对我使用3个空格以及其他东西感到不满意。 这是web.config:

<?xml version="1.0" encoding="utf-8"?>
<!--
    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>
        <clear/>
        <!--  <add name="DefaultConnection" connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=aspnet-FSISIssues7-20150731095953;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnet-FSISIssues7-20150731095953.mdf" providerName="System.Data.SqlClient" />-->
        <add name="FSIS-IssuesConnection" connectionString="Data Source=LARRY-GATEWAY\SQLEXPRESS;Initial Catalog=FSIS-Issues;Integrated Security=True"
            providerName="System.Data.SqlClient" />
         <add name="LocalSqlServer" connectionString="Data Source=LARRY-GATEWAY\SQLEXPRESS;Initial Catalog=FSIS-Issues;Integrated Security=True"
            providerName="System.Data.SqlClient" />
         <add name="SqlRoleManager" connectionString="Data Source=LARRY-GATEWAY\SQLEXPRESS;Initial Catalog=FSIS-Issues;Integrated Security=True"
            providerName="System.Data.SqlClient" />

    </connectionStrings>
    <system.web>
        <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="FSIS-IssuesConnection"
                applicationName="FSISIssues" />
            </providers>
        </roleManager>
        <compilation debug="true" targetFramework="4.5" />
        <httpRuntime targetFramework="4.5" />
        <pages>
            <namespaces>
                <add namespace="System.Web.Optimization" />
            </namespaces>
        <controls>
            <add assembly="Microsoft.AspNet.Web.Optimization.WebForms" namespace="Microsoft.AspNet.Web.Optimization.WebForms" tagPrefix="webopt" />
        </controls></pages>
        <authentication mode="Windows">

            <!-- <forms loginUrl="~/Account/Login" timeout="2880" defaultUrl="~/" />  -->
        </authentication>
        <profile defaultProvider="SqlRoleManager">
            <providers>
                <clear/>

                <add name="SqlRoleManager"

                    type="System.Web.Security.SqlRoleProvider"

                    connectionStringName="FSIS-IssuesConnection"

                    applicationName="FSISIssues" />
            </providers>
        </profile>
            <membership defaultProvider="DefaultMembershipProvider">
                  <providers>
                        <add name="DefaultMembershipProvider" type="System.Web.Providers.DefaultMembershipProvider, System.Web.Providers, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="FSIS-IssuesConnection" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" applicationName="FSISIssues" />
                  </providers>
            </membership>
            <!--<roleManager  enabled="true" defaultProvider="SQLRoleProvider">


              <providers>
                    <add name="DefaultRoleProvider" type="System.Web.Providers.DefaultRoleProvider, System.Web.Providers, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="FSIS-IssuesConnection" applicationName="FSISIssues" />
              </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">
                <providers>
                    <add name="DefaultSessionProvider" type="System.Web.Providers.DefaultSessionStateProvider, System.Web.Providers, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="FSIS-IssuesConnection" />
                </providers>
        </sessionState>
  </system.web>
      <runtime>
            <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
                  <dependentAssembly>
                        <assemblyIdentity name="DotNetOpenAuth.Core" publicKeyToken="2780ccd10d57b246" />
                        <bindingRedirect oldVersion="1.0.0.0-4.0.0.0" newVersion="4.1.0.0" />
                  </dependentAssembly>
                  <dependentAssembly>
                        <assemblyIdentity name="DotNetOpenAuth.AspNet" publicKeyToken="2780ccd10d57b246" />
                        <bindingRedirect oldVersion="1.0.0.0-4.0.0.0" newVersion="4.1.0.0" />
                  </dependentAssembly>
                  <dependentAssembly>
                        <assemblyIdentity name="EntityFramework" publicKeyToken="b77a5c561934e089" />
                        <bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.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>

2 个答案:

答案 0 :(得分:0)

我相信这是因为,

  

成员资格数据库也存储为App_Data中的.mdf文件   夹。第一个用户拥有后,您将能够查看此数据库   登录此Web应用程序。

答案 1 :(得分:0)

经过长时间的沮丧搜索后,我终于找到了获取用户的方法(Windows身份验证)。 HttpContext.Current.Request.LogonUserIdentity.Name适合我。我无法相信我最终偶然发现了它。我讨厌取决于神秘的框架!