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



我正在使用成员资格、windows授权和sqlprovider创建一个小型的asp.net web表单应用程序。aspnet表是使用sqlexpress数据库中的aspnet_regsql.exe工具创建的(与非成员身份内容的数据库相同(。在default.aspx的page_load中,我创建了一个用户:var x=System.Web.Security.Membersation.CreateUser(@"larry gateway\larry","Gilmgilm1"(;我使用以下方法测试其存在:var me_the_User=System.Web.Security.Membersation.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-GATEWAYSQLEXPRESS;Initial Catalog=FSIS-Issues;Integrated Security=True"
            providerName="System.Data.SqlClient" />
         <add name="LocalSqlServer" connectionString="Data Source=LARRY-GATEWAYSQLEXPRESS;Initial Catalog=FSIS-Issues;Integrated Security=True"
            providerName="System.Data.SqlClient" />
         <add name="SqlRoleManager" connectionString="Data Source=LARRY-GATEWAYSQLEXPRESS;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_Data中文件夹一旦第一个用户已登录到此web应用程序。

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

相关内容

最新更新