2014-12-03 111 views
0

大家好,我正在管理一個用asp.net mvc4編寫的網站。不過,我對我想發佈的佈局和CSS樣式進行了一些更改,以更新當前網站。發佈之前一切工作正常,當我在發佈的過程中,我確保我沒有觸摸web.config文件,我只檢查了我想更新的文件,這主要是一個Html和CSS的變化。發佈網站後出現錯誤

發佈後,我試圖登錄,我開始一個錯誤說

Error 
An error occurred while processing your request. 

請幫助我。我可以提供其他任何可以幫助我解決此問題的信息。

,當我試圖在一個我對我的本地主機我得到這個錯誤

You must call the "WebSecurity.InitializeDatabaseConnection" method before you call any other method of the "WebSecurity" class. This call should be placed in an _AppStart.cshtml file in the root of your site. 

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: You must call the "WebSecurity.InitializeDatabaseConnection" method before you call any other method of the "WebSecurity" class. This call should be placed in an _AppStart.cshtml file in the root of your site. 

Source Error: 


Line 36:   public ActionResult Login(LoginModel model, string returnUrl) 
Line 37:   { 
Line 38:    if (ModelState.IsValid && WebSecurity.Login(model.UserName, model.Password, persistCookie: model.RememberMe)) 
Line 39:    { 
Line 40:     //return RedirectToLocal(returnUrl); 

Source File: c:\Users\IBN HAMZA\Documents\Visual Studio 2012\Projects\Zedvance\Zedvance\Controllers\AccountController.cs Line: 38 

Stack Trace: 


[InvalidOperationException: You must call the "WebSecurity.InitializeDatabaseConnection" method before you call any other method of the "WebSecurity" class. This call should be placed in an _AppStart.cshtml file in the root of your site.] 
    WebMatrix.WebData.SimpleMembershipProvider.VerifyInitialized() +50 
    WebMatrix.WebData.WebSecurity.VerifyProvider() +36 
    WebMatrix.WebData.WebSecurity.Login(String userName, String password, Boolean persistCookie) +14 
    Zedvance.Controllers.AccountController.Login(LoginModel model, String returnUrl) in c:\Users\IBN HAMZA\Documents\Visual Studio 2012\Projects\Zedvance\Zedvance\Controllers\AccountController.cs:38 
    lambda_method(Closure , ControllerBase , Object[]) +147 
    System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters) +14 
    System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters) +182 
    System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +27 
    System.Web.Mvc.Async.<>c__DisplayClass42.<BeginInvokeSynchronousActionMethod>b__41() +28 
    System.Web.Mvc.Async.<>c__DisplayClass8`1.<BeginSynchronous>b__7(IAsyncResult _) +10 
    System.Web.Mvc.Async.WrappedAsyncResult`1.End() +50 
    System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult) +32 
    System.Web.Mvc.Async.<>c__DisplayClass39.<BeginInvokeActionMethodWithFilters>b__33() +58 
    System.Web.Mvc.Async.<>c__DisplayClass4f.<InvokeActionMethodFilterAsynchronously>b__49() +225 
    System.Web.Mvc.Async.<>c__DisplayClass4f.<InvokeActionMethodFilterAsynchronously>b__49() +225 
    System.Web.Mvc.Async.<>c__DisplayClass37.<BeginInvokeActionMethodWithFilters>b__36(IAsyncResult asyncResult) +10 
    System.Web.Mvc.Async.WrappedAsyncResult`1.End() +50 
    System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethodWithFilters(IAsyncResult asyncResult) +34 
    System.Web.Mvc.Async.<>c__DisplayClass2a.<BeginInvokeAction>b__20() +24 
    System.Web.Mvc.Async.<>c__DisplayClass25.<BeginInvokeAction>b__22(IAsyncResult asyncResult) +99 
    System.Web.Mvc.Async.WrappedAsyncResult`1.End() +50 
    System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult) +27 
    System.Web.Mvc.<>c__DisplayClass1d.<BeginExecuteCore>b__18(IAsyncResult asyncResult) +14 
    System.Web.Mvc.Async.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) +23 
    System.Web.Mvc.Async.WrappedAsyncResult`1.End() +55 
    System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +39 
    System.Web.Mvc.Async.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) +23 
    System.Web.Mvc.Async.WrappedAsyncResult`1.End() +55 
    System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) +29 
    System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.EndExecute(IAsyncResult asyncResult) +10 
    System.Web.Mvc.<>c__DisplayClass8.<BeginProcessRequest>b__3(IAsyncResult asyncResult) +25 
    System.Web.Mvc.Async.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) +23 
    System.Web.Mvc.Async.WrappedAsyncResult`1.End() +55 
    System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +31 
    System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +9 
    System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +9657896 
    System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155 
+1

集'通過在你的web.config'檢查完整的錯誤 – 2014-12-03 11:58:20

+0

@Vsevolod我應該做的活網站或我的本地主機? – ibnhamza 2014-12-03 12:00:59

+0

如果它在您的本地主機網站上運行,並且不在您的現場網站上,則在那裏執行。如果它不能在你的本地站點上運行,那麼你應該得到YSOD,或者在你的VS – 2014-12-03 12:09:10

回答

0

看到你所得到的錯誤後,這個問題似乎是事實,你叫WebSecurity初始化連接之前。

編輯拋出這樣的錯誤文件:

public ActionResult Login(LoginModel model, string returnUrl) 
{ 
    if (!WebSecurity.Initialized) 
    { 
     WebSecurity.InitializeDatabaseConnection("DefaultConnection", "UserProfile", "UserId", "UserName", autoCreateTables: true); 
    } 
+0

對不起,我不明白「修復它的唯一方法的確是重新部署整個網站,除非你的web.config文件是例外。不會影響數據庫? – ibnhamza 2014-12-03 12:17:33

+0

您的數據庫不在遠程位置嗎?像SQL Server一樣? – 2014-12-03 12:18:37

+0

檢查我更新的答案。 – 2014-12-03 12:22:42