我使用asp.net mvc3编写了一个网站,并使用Membership类进行用户管理 在VS2010中我的本地主机服务器上的一切正常,但当我将其部署到服务器时,我有一些错误:
Event code: 3005
Event message: An unhandled exception has occurred.
Event time: 7/23/2011 3:30:31 PM
Event time (UTC): 7/23/2011 10:30:31 PM
Event ID: 5afe87171ad743d39bf87e29f8501615
Event sequence: 7785
Event occurrence: 49
Event detail code: 0
Application information:
Application domain: /LM/W3SVC/3/ROOT-3-129559136991646761
Trust level: Full
Application Virtual Path: /
Application Path: C:\inetpub\wwwroot\bandarMVC\
Machine name: BANDARPAYANE
Process information:
Process ID: 2612
Process name: w3wp.exe
Account name: IIS APPPOOL\MVC
Exception information:
Exception type: IndexOutOfRangeException
Exception message: Index was outside the bounds of the array.
at System.Data.SqlClient.SqlDataReader.ReadColumn(Int32 i, Boolean setTimeout)
at System.Data.SqlClient.SqlDataReader.GetInt32(Int32 i)
at System.Web.Security.SqlMembershipProvider.GetPasswordWithFormat(String username, Boolean updateLastLoginActivityDate, Int32& status, String& password, Int32& passwordFormat, String& passwordSalt, Int32& failedPasswordAttemptCount, Int32& failedPasswordAnswerAttemptCount, Boolean& isApproved, DateTime& lastLoginDate, DateTime& lastActivityDate)
at System.Web.Security.SqlMembershipProvider.CheckPassword(String username, String password, Boolean updateLastLoginActivityDate, Boolean failIfNotApproved, String& salt, Int32& passwordFormat)
at System.Web.Security.SqlMembershipProvider.ValidateUser(String username, String password)
at BandarMVC.Controllers.AccountController.LogOn(LogOnModel model, String returnUrl) in C:\Users\Javad\Documents\Visual Studio 2010\Projects\BandarMVC\BandarMVC\Controllers\AccountController.cs:line 40
at lambda_method(Closure , ControllerBase , Object[] )
at System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters)
at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters)
at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClass15.<InvokeActionMethodWithFilters>b__12()
at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation)
at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodWithFilters(ControllerContext controllerContext, IList`1 filters, ActionDescriptor actionDescriptor, IDictionary`2 parameters)
at System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName)
at System.Web.Mvc.Controller.ExecuteCore()
at System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext)
at System.Web.Mvc.MvcHandler.<>c__DisplayClass6.<>c__DisplayClassb.<BeginProcessRequest>b__5()
at System.Web.Mvc.Async.AsyncResultWrapper.<>c__DisplayClass1.<MakeVoidDelegate>b__0()
at System.Web.Mvc.MvcHandler.<>c__DisplayClasse.<EndProcessRequest>b__d()
at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
Request information:
Request URL: http://10.1.1.90/Account/LogOn?ReturnUrl=/
Request path: /Account/LogOn
User host address: 10.1.1.90
User:
Is authenticated: False
Authentication Type:
Thread account name: IIS APPPOOL\MVC
Thread information:
Thread ID: 26
Thread account name: IIS APPPOOL\MVC
Is impersonating: False
Stack trace: at System.Data.SqlClient.SqlDataReader.ReadColumn(Int32 i, Boolean setTimeout)
at System.Data.SqlClient.SqlDataReader.GetInt32(Int32 i)
at System.Web.Security.SqlMembershipProvider.GetPasswordWithFormat(String username, Boolean updateLastLoginActivityDate, Int32& status, String& password, Int32& passwordFormat, String& passwordSalt, Int32& failedPasswordAttemptCount, Int32& failedPasswordAnswerAttemptCount, Boolean& isApproved, DateTime& lastLoginDate, DateTime& lastActivityDate)
at System.Web.Security.SqlMembershipProvider.CheckPassword(String username, String password, Boolean updateLastLoginActivityDate, Boolean failIfNotApproved, String& salt, Int32& passwordFormat)
at System.Web.Security.SqlMembershipProvider.ValidateUser(String username, String password)
at BandarMVC.Controllers.AccountController.LogOn(LogOnModel model, String returnUrl) in C:\Users\Javad\Documents\Visual Studio 2010\Projects\BandarMVC\BandarMVC\Controllers\AccountController.cs:line 40
at lambda_method(Closure , ControllerBase , Object[] )
at System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters)
at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters)
at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClass15.<InvokeActionMethodWithFilters>b__12()
at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation)
at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodWithFilters(ControllerContext controllerContext, IList`1 filters, ActionDescriptor actionDescriptor, IDictionary`2 parameters)
at System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName)
at System.Web.Mvc.Controller.ExecuteCore()
at System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext)
at System.Web.Mvc.MvcHandler.<>c__DisplayClass6.<>c__DisplayClassb.<BeginProcessRequest>b__5()
at System.Web.Mvc.Async.AsyncResultWrapper.<>c__DisplayClass1.<MakeVoidDelegate>b__0()
at System.Web.Mvc.MvcHandler.<>c__DisplayClasse.<EndProcessRequest>b__d()
at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
Custom event details:
有没有人知道这个错误的原因和解决方案?
以下代码抛出此异常:
[HttpPost]
public ActionResult LogOn(LogOnModel model, string returnUrl)
{
BuildMenu();
if (ModelState.IsValid)
{
-------> if (Membership.ValidateUser(model.UserName, model.Password)) <----------------
{
FormsAuthentication.SetAuthCookie(model.UserName, model.RememberMe);
if (Url.IsLocalUrl(returnUrl) && returnUrl.Length > 1 && returnUrl.StartsWith("/")
&& !returnUrl.StartsWith("//") && !returnUrl.StartsWith("/\\"))
{
return Redirect(returnUrl);
}
else
{
return RedirectToAction("Index", "Home");
}
}
else
{
ModelState.AddModelError("", "نام کاربر و یا شناسه عبور صحیح نمی باشد");
}
}
// If we got this far, something failed, redisplay form
return View(model);
}
答案 0 :(得分:1)
使用某些旧版本的.NET Framework aspnet_regsql.exe实用程序创建部署应用程序时,您所连接的数据库看起来就像。尝试creating and configuring the membership database使用您在本地使用的aspnet_regsql
版本。或者在本地,您只需使用SQL Express和~/App_Data
文件夹。