1

我首先使用实体​​框架代码设置了一个数据库。我已经设置了所有 asp.net 用户角色管理的东西。我有一个用户我已经使用了一段时间,它工作正常,我刚刚添加了另一个用户,我可以正常登录。我想设置角色(我将其命名为两个:管理员和用户)。我的角色设置得很好,但是当我尝试将我的用户添加到角色时,我收到以下错误(我正在使用 webadmin 工具):

An error was encountered. Please return to the previous page and try again. 

The following message may help in diagnosing the problem: The user 'userName' was 
not found. at System.Web.Administration.WebAdminPage.CallWebAdminHelperMethod(Boolean 
isMembership, String methodName, Object[] parameters, Type[] paramTypes) at 
ASP.security_roles_managesinglerole_aspx.EnabledChanged(Object sender, EventArgs e) at 
System.Web.UI.WebControls.CheckBox.OnCheckedChanged(EventArgs e) at 
System.Web.UI.WebControls.CheckBox.RaisePostDataChangedEvent() at 
System.Web.UI.WebControls.CheckBox.System.Web.UI.IPostBackDataHandler.RaisePostDataChangedEvent()
at System.Web.UI.Page.RaiseChangedEvents() at 
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean 
includeStagesAfterAsyncPoint)

我阅读了几个关于此的问题,并尝试更新网络配置,但没有奏效。这是我当前的 web.config 设置:

<roleManager enabled="true" defaultProvider="DefaultRoleProvider">
  <providers>
    <remove name="DefaultRoleProvider"/>
    <add connectionStringName="NerdlyContext" applicationName="/"
      name="DefaultRoleProvider" type="System.Web.Providers.DefaultRoleProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
  </providers>
</roleManager>

如果我使用 SSMS,我可以看到正确填充的用户和角色表。我有 UsersInRoles 表,但它是空的。

这是一个使用 .net 4.0 的 asp.net MVC4 应用程序。

这是完整的、经过消毒的 web.config

<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=4.3.1.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<connectionStrings>
<remove name="LocalSqlServer"/>
<add name="LocalSqlServer" providerName="System.Data.SqlClient" connectionString="Data Source=tcp:sql2k804.discountasp.net;Initial Catalog=boobs;User ID=boobs;Password=boobs;" />
</connectionStrings>
<appSettings>
<add key="webpages:Version" value="2.0.0.0" />
<add key="webpages:Enabled" value="false" />
<add key="PreserveLoginUrl" value="true" />
<add key="ClientValidationEnabled" value="true" />
<add key="UnobtrusiveJavaScriptEnabled" value="true" />
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.0" />
<httpRuntime />
<machineKey />
<authentication mode="Forms">
  <forms loginUrl="~/Account/Login" timeout="2880" />
</authentication>
<pages controlRenderingCompatibilityVersion="4.0">
  <namespaces>
    <add namespace="System.Web.Helpers" />
    <add namespace="System.Web.Mvc" />
    <add namespace="System.Web.Mvc.Ajax" />
    <add namespace="System.Web.Mvc.Html" />
    <add namespace="System.Web.Optimization" />
    <add namespace="System.Web.Routing" />
    <add namespace="System.Web.WebPages" />
  </namespaces>
</pages>
<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="LocalSqlServer" applicationName="/" />
  </providers>
</profile>
<membership defaultProvider="DefaultMembershipProvider">
  <providers>
    <add connectionStringName="LocalSqlServer" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" applicationName="NerdlyThings" name="DefaultMembershipProvider" type="System.Web.Providers.DefaultMembershipProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
  </providers>
</membership>
<roleManager enabled="true" defaultProvider="DefaultRoleProvider">
  <providers>
    <add connectionStringName="LocalSqlServer" applicationName="/" name="DefaultRoleProvider" type="System.Web.Providers.DefaultRoleProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
  </providers>
</roleManager>
<sessionState mode="InProc" customProvider="DefaultSessionProvider">
  <providers>
    <add name="DefaultSessionProvider" type="System.Web.Providers.DefaultSessionStateProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="LocalSqlServer" />
  </providers>
</sessionState>

此外,当我将其更改为使用旧的 SQL 提供程序时,我只是得到一个不同的错误,说它不喜欢我的架构版本?

4

0 回答 0