在asp.net网页中尝试WebSecurity.CreateAccount时遇到错误’提供
发布时间:2020-12-16 04:33:26 所属栏目:asp.Net 来源:网络整理
导读:我是asp.net的新手.我正在尝试使用WebMatrix创建一个简单的登录和注册网页.但是当我尝试创建帐户时出现以下错误: The Provider encountered an unknown error.Description: An unhandled exception occurred during the execution of the current web reque
我是asp.net的新手.我正在尝试使用WebMatrix创建一个简单的登录和注册网页.但是当我尝试创建帐户时出现以下错误:
The Provider encountered an unknown error. 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.Web.Security.MembershipCreateUserException: The Provider encountered an unknown error. Source Error: Line 32: db.Execute("INSERT INTO UserData (Email,Name) VALUES (@0,@1)",email,username); Line 33: Line 34: WebSecurity.CreateAccount(email,password); Line 35: Response.Redirect("Homepage.cshtml"); Line 36: } Source File: c:UsersadminDocumentsMy Web SitesLoginRegister.cshtml Line: 34 Stack Trace: [MembershipCreateUserException: The Provider encountered an unknown error.] WebMatrix.WebData.SimpleMembershipProvider.CreateAccount(String userName,String password,Boolean requireConfirmationToken) +1312 WebMatrix.WebData.WebSecurity.CreateAccount(String userName,Boolean requireConfirmationToken) +31 ASP._Page_Register_cshtml.Execute() in c:UsersadminDocumentsMy Web SitesLoginRegister.cshtml:34 System.Web.WebPages.WebPageBase.ExecutePageHierarchy() +207 System.Web.WebPages.WebPage.ExecutePageHierarchy(IEnumerable`1 executors) +68 System.Web.WebPages.WebPage.ExecutePageHierarchy() +156 System.Web.WebPages.StartPage.RunPage() +19 System.Web.WebPages.StartPage.ExecutePageHierarchy() +65 System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext,TextWriter writer,WebPageRenderingBase startPage) +76 System.Web.WebPages.WebPageHttpHandler.ProcessRequestInternal(HttpContextBase httpContext) +119 Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.272 任何帮助表示赞赏.谢谢. 解决方法
务必:
>首先创建用户记录 以下是我的代码,它解决了您遇到的同一问题: public ActionResult SignUp(SignUpModel model) { if (ModelState.IsValid) { using (MorphometryContext context = new MorphometryContext()) { User user = new User { Email = model.Email,FirstName = model.FirstName,LastName = model.LastName,Username = model.UserName }; context.Users.Add(user); context.SaveChanges(); } // Attempt to register the user try { WebSecurity.CreateAccount(model.UserName,model.Password); } catch (MembershipCreateUserException e) { ModelState.AddModelError("",ErrorCodeToString(e.StatusCode)); return View(); } WebSecurity.Login(model.UserName,model.Password); return RedirectToAction("Index","Projects"); } 此外,您不希望Respoonse.Redirect到.cshtml文件.相反,您应该返回RedirectToAction并传入Action和Controller名称. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- ASP.NET 4.0中最好的浏览器检测解决方案
- AutoMapper系列:介绍、使用
- ASP.NET MVC ViewEngine ViewLocationCache.GetViewLocatio
- asp.net-mvc如何更改宽度Html.TextBox
- asp.net-mvc – ASP.NET MVC授权和使用模型类的权限
- asp.net-mvc – 将html属性传递给Html.Actionlink帮助函数
- asp.net-mvc – ASP.NET MVC WebApi:没有为此对象定义的无
- 验证 – ASP.NET和EF Core – 对于由Scaffold-DbContext生成
- asp.net – Mono vhost配置错误:地址已经在使用
- asp.net – 发布管理 – 发布给用户的一小部分 – 它对于面
推荐文章
站长推荐
- asp.net – 我应该继续研究MVC 1.0上的项目还是停
- asp.net – dotnet运行OR dotnet手表与开发环境从
- asp.net-mvc – 在ASP.NET MVC中从相同的路由URL
- asp.net – 动态加载不同控件时无法加载viewstat
- asp.net – 在编辑模式下未选择的Html.DropDownL
- asp.net-mvc – 域实体,DTO和查看模型
- asp.net – Viewstate vs Postback
- asp.net – 无法在嵌入式ASPX代码中引用动态对象
- 清除ASP.NET临时文件缓存的麻烦
- asp.net-mvc-3 – ASP.NET MVC DropDownListFor从
热点阅读