Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/332.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# MVC3/MVC4中的简单成员身份和角色提供程序_C#_Asp.net Mvc 3_Asp.net Mvc 4_Membership Provider_Roleprovider - Fatal编程技术网

C# MVC3/MVC4中的简单成员身份和角色提供程序

C# MVC3/MVC4中的简单成员身份和角色提供程序,c#,asp.net-mvc-3,asp.net-mvc-4,membership-provider,roleprovider,C#,Asp.net Mvc 3,Asp.net Mvc 4,Membership Provider,Roleprovider,我正在编写简单的成员资格和角色提供程序。 我正在尝试从post运行代码,但在运行IIS时显示错误: Configuration Error Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your config

我正在编写简单的成员资格和角色提供程序。 我正在尝试从post运行代码,但在运行IIS时显示错误:

Configuration Error
Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately.

Line 39:       <providers>
Line 40:         <clear />
Line 41:         <add name="LocalBankMembershipProvider" type="LocalBank.Helpers.LocalBankMembershipProvider, LocalBank" connectionStringName="LocalBankEntities" />
Line 42:       </providers>
Line 43:     </membership>

Message Parser Error: Target call threw an exception.
Line: 41
配置错误
描述:处理服务此请求所需的配置文件时出错。请查看下面的特定错误详细信息,并适当修改配置文件。
第39行:
第40行:
第41行:
第42行:
第43行:
消息分析器错误:目标调用引发异常。
第41行
我在项目开始时犯了什么错误? 使用Nuget包将项目从mvc3转换为mvc4


如何修复此错误?

您是否遵循了同一链接评论部分中给出的建议

有几件事可以尝试:

  • 可能是连接字符串出错,因此您会看到此错误。更改连接字符串(例如数据源)。如果您仍然看到一个问题,调试项目,看看它到底在哪里被卡住了,以及您可以得到更多的信息。我能够重现这个问题,通过更改连接字符串,它得到了解决

  • 调试时,您将看到它在检查角色存在时将抛出异常。根据博客,您需要添加默认角色“经理”:

  • 唯一需要注意的是没有创建任何角色。如果查看AccountController Register HttpPost操作,您会注意到通过此站点注册的任何用户都会被授予默认角色“Member”。这是可以更改的,但无论这是什么角色,都必须首先在角色表中创建。您可以通过编写脚本(很可能是首选方法)来实现这一点,也可以编写一些黑客代码并快速调用,因为在首次创建角色时只需运行一次。下面是一些示例代码,您可以使用这些代码创建“成员”角色,并根据需要对其进行修改

    从代码中的某个地方调用这3行代码(或单独的 从那时起,代码应该按照 预期。很抱歉给你带来了困惑

    如果您仍然面临问题,请分享更多详细信息。希望这有帮助

    LocalBankRepository repo = new LocalBankRepository(); 
    repo.AddRole("Member"); 
    repo.Save();