asp.net-mvc – WebSecurity.InitializeDatabaseConnection方法只能调用一次

前端之家收集整理的这篇文章主要介绍了asp.net-mvc – WebSecurity.InitializeDatabaseConnection方法只能调用一次前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在尝试 Windows Azure来托管一个MVC4 Web应用程序.
我创建了一个测试应用程序,使用VS2012 MVC4互联网应用程序模板,并添加了一个自定义的模型和控制器.

我已经在Azure上发布了它,并设法将“update-database”应用于Azure数据库.

当我在本地尝试应用程序,但使用Azure sql数据库,它的工作正常.
我可以登录/注册并使用我的测试控制器.

当我在线尝试应用程序,我可以使用测试控制器,但登录注册链接给出以下异常:

Server Error in '/' Application.

The "WebSecurity.InitializeDatabaseConnection" method can be called only once.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.InvalidOperationException: The "WebSecurity.InitializeDatabaseConnection" method can be called only once.

Source Error: 

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace: 


[InvalidOperationException: The "WebSecurity.InitializeDatabaseConnection" method can be called only once.]
   WebMatrix.WebData.WebSecurity.InitializeMembershipProvider(SimpleMembershipProvider simpleMembership,DatabaseConnectionInfo connect,String userTableName,String userIdColumn,String userNameColumn,Boolean createTables) +123
   WebMatrix.WebData.WebSecurity.InitializeProviders(DatabaseConnectionInfo connect,Boolean autoCreateTables) +51
   WebMatrix.WebData.WebSecurity.InitializeDatabaseConnection(String connectionStringName,Boolean autoCreateTables) +52
   MembershipTest2.Filters.SimpleMembershipInitializer..ctor() +193

你有什么想法来自哪里?
如果我调试(本地版本),此方法调用一次.

谢谢.

解决方法

您可以尝试将该调用封装到该方法中,以确保不再调用一次
if (!WebMatrix.WebData.WebSecurity.Initialized)
                {
                    WebSecurity.InitializeDatabaseConnection(...);
                }
原文链接:https://www.f2er.com/aspnet/249706.html

猜你在找的asp.Net相关文章