在asp.net网页中尝试WebSecurity.CreateAccount时遇到错误’提供程序遇到未知错误’
发布时间:2020-05-25 08:59:49 所属栏目:asp.Net 来源:互联网
导读:我是asp.net的新手.我正在尝试使用WebMatrix创建一个简单的登录和注册网页.但是当我尝试创建帐户时出现以下错误: The Provider encountered an unknown error.Description: An unhandled exception occurred during the execution of the current web reques
|
我是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-core – RemoteIpAddress始终为null
- asp.net – XmlSerializer可以反序列化为Nullable吗?
- asp.net-core – ASP.NET Core WebAPI默认路由不起作用
- asp.net-mvc – C#MVC FindPartialView无法找到路径
- asp.net – 使用Entity Framework的仓库模式(mvc storefron
- asp.net – 点击按钮禁用
- asp.net-mvc-routing – ASP MVC 5属性路由VS.基于公约的路
- 将Funscript添加到现有的ASP.NET MVC项目中
- 实体框架 – 实体框架验证混淆 – 最大字符串长度为’128′
- Asp.net复选框和html数据属性
推荐文章
站长推荐
- asp.net-mvc – LinkedIn登录ASP.NET MVC 5应用程
- asp.net – System.Data.OleDb.OleDbException:
- asp.net-mvc – Razor查看引擎在VB.NET中的怪癖
- asp.net – 可以在Visual Studio 2010中将任务列
- 如何在使用ASP.NET MVC的jQuery AJAX调用中触发“
- asp.net-web-api – 在Visual Studio中启动WebAP
- asp.net – 我可以在GoDaddy上使用NHibernate吗?
- asp.net-web-api – WebAPI 2属性路由启用会话状
- asp.net-mvc – 逐渐将现有的ASP.NET站点转换为M
- asp.net-mvc – 在存储库之间调用方法 – 存储库
热点阅读
