Asp.net aspnet#u users表为空,但c#代码表示存在用户

Asp.net aspnet#u users表为空,但c#代码表示存在用户,asp.net,.net,Asp.net,.net,我正在使用成员资格、windows授权和sqlprovider创建一个小型asp.net webforms应用程序。aspnet表是使用sqlexpress数据库中的aspnet_regsql.exe工具创建的(与非成员内容数据库相同)。在default.aspx.cs的页面中,我创建了一个用户: var x=System.Web.Security.Membership.CreateUser(@“larry gateway\larry”,“Gilmgilm1”); 我使用以下方法测试其存在性:

我正在使用成员资格、windows授权和sqlprovider创建一个小型asp.net webforms应用程序。aspnet表是使用sqlexpress数据库中的aspnet_regsql.exe工具创建的(与非成员内容数据库相同)。在default.aspx.cs的页面中,我创建了一个用户: var x=System.Web.Security.Membership.CreateUser(@“larry gateway\larry”,“Gilmgilm1”); 我使用以下方法测试其存在性: var me_the_User=System.Web.Security.Membership.GetUser(@“larry gateway\larry”); 我得到一个物体。 我尝试再次添加它,但失败-重复。 但我在aspnet_用户中查找,它是空的! 所以我必须在不同的数据库中创建它,而不是。\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>

我相信这是因为

成员资格数据库也作为.mdf文件存储在App_数据中 文件夹。第一个用户访问完后,您将能够查看此数据库 已登录到此web应用程序


经过长时间令人沮丧的搜索,我终于找到了一种获取用户的方法(windows身份验证)。HttpContext.Current.Request.LogonUserIdentity.Name适合我。我真不敢相信我终于偶然发现了。我讨厌依赖神秘的框架

@Ethan:谢谢你。我运行了它,但app_数据中没有db(不在解决方案资源管理器中,也不在文件(Windows资源管理器)中)。也没有向我的aspnet_用户表添加任何条目。我正在使用Windows身份验证(intranet应用程序)还记得在某个地方看到,在这种情况下,向aspnet_用户添加用户是不必要的。这对我来说没有意义,因为aspnet_usersInRoles需要UserID和RoleID。要获得有效的UserID,我需要aspnet_users表中的一个用户。