这是我在身份中注册的代码:
[AllowAnonymous]
public ActionResult Register()
{
var roles = db.Roles.Select(r => new { RoleID = r.Id, RoleName = r.Name }).ToList();
ViewBag.Roles = new SelectList(roles, "RoleID", "RoleName");
return View();
}
//
// POST: /Account/Register
[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public async Task<ActionResult> Register(RegisterViewModel model, HttpPostedFileBase UserPhoto)
{
if (ModelState.IsValid)
{
model.DateRegister = DateTime.Now;
var user = new ApplicationUser
{
UserName = model.UserName,
Name = model.Name,
Family = model.Family,
PhoneNumber = model.PhoneNumber,
Gender = model.Gender,
BirthDay = model.BirthDay,
DateRegister = model.DateRegister,
IsActive = false,
Email = model.Email
};
if (UserPhoto != null)
{
UserPhoto = Request.Files[0];
var ext = System.IO.Path.GetExtension(UserPhoto.FileName);
if (ext == ".jpeg" || ext == ".jpg" || ext == ".png")
{
string filename = model.PhoneNumber + ext;
UserPhoto.SaveAs(Server.MapPath(@"~/Image/" + filename));
user.UserPhoto = filename;
}
}
var result = await UserManager.CreateAsync(user, model.Password);
if (result.Succeeded)
{
await SignInManager.SignInAsync(user, isPersistent: false, rememberBrowser: false);
await UserManager.AddToRoleAsync(user.Id,model.UserRoles);
return RedirectToAction("Index", "Home");
}
AddErrors(result);
}
return View(model);
}
WebConf:
<appSettings>
<add key="webpages:Version" value="3.0.0.0" />
<add key="webpages:Enabled" value="false" />
<add key="ClientValidationEnabled" value="true" />
<add key="UnobtrusiveJavaScriptEnabled" value="true" />
<add key="owin:AutomaticAppStartup" value="false" />
<add key="owin:AppStartup" value="Identity_Work.Startup" />
</appSettings>
但是我收到了这个错误:
问题是什么?我该如何解决?
答案 0 :(得分:8)
根据之前的对话,您确认了
[assembly: OwinStartup(typeof(Identity_Work.Startup))]
已存在于Startup.cs
。
这意味着web.config中不再需要owin:AppStartup
。
因此,appSettings
应该是这样的。
<appSettings>
<add key="webpages:Version" value="3.0.0.0" />
<add key="webpages:Enabled" value="false" />
<add key="ClientValidationEnabled" value="true" />
<add key="UnobtrusiveJavaScriptEnabled" value="true" />
<add key="owin:AutomaticAppStartup" value="true" /> <!-- This should be true -->
</appSettings>