【发布时间】:2013-01-31 21:01:03
【问题描述】:
我是 Visual Studio 2012 / ASP.NET 4.5 Web 表单的新手。
我正在尝试在我的asp.net 4.5 web forms 应用程序(使用Visual Studio 2012)中使用表单身份验证(ASP.NET 成员身份),因为我已经多次成功使用asp.net version 4.0。
问题似乎是,当我在Visual Studio 2012 中进行测试时,它无法识别我的web.config 设置指向SQL Server 2008R2 aspnetdb。它似乎正在使用SQL Express aspnetdb.mdf 文件来存储我的用户。
我尝试从我的网络应用程序中完全删除 aspnetdb.mdf,但它仍然无法识别指向 SQL Server 的 web.config 设置,而是使用其他地方的设置(不知道在哪里!) .我知道这一点是因为如果我不提供问题和答案作为参数,Membership.CreateUser() 方法会引发错误。此外,Web 配置工具需要问答才能创建新用户。我的web.config 设置特别没有!
当我托管 Web 应用程序时,它会在 SQL Server 数据库中查找我的用户,因为当我尝试使用使用 VS2012 中的 Web 配置工具成功创建的用户名登录时,我的应用程序找不到该用户!它似乎在SQL Server 中查找,但找不到。
我一定错过了一些基本设置...有人有什么想法吗?
我在下面包含了我的 web.config 设置:
<connectionStrings>
<add name="ApplicationServices" connectionString="Data Source=localhost;Initial Catalog=aspnetdb;Persist Security Info=True;User ID=studentid;Password=password" providerName="System.Data.SqlClient"/>
<add name="StudentAttendanceConnectionString" connectionString="Data Source=localhost;Initial Catalog=StudentAttendance;Persist Security Info=True;User ID=studentid;Password=password" providerName="System.Data.SqlClient"/>
</connectionStrings>
<authentication mode="Forms">
<forms loginUrl="~/Account/Login.aspx" timeout="2880"/>
</authentication>
<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="ApplicationServices" applicationName="/"/>
</providers>
</profile>
<membership>
<providers>
<add connectionStringName="ApplicationServices" enablePasswordRetrieval="true"
enablePasswordReset="false" requiresQuestionAndAnswer="false"
requiresUniqueEmail="false" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6"
minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10"
applicationName="/" name="DefaultMembershipProvider" type="System.Web.Providers.DefaultMembershipProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
</providers>
</membership>
<roleManager>
<providers>
<add connectionStringName="ApplicationServices" applicationName="/"
name="DefaultRoleProvider" type="System.Web.Providers.DefaultRoleProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
</providers>
</roleManager>
【问题讨论】:
标签: asp.net sql sql-server-2008-r2 membership-provider