0
我有一个表格来管理的意见插入:重定向后登录无法工作
@model GatorsWebSite.Comment
@using (Html.BeginForm("Create", "Comments", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
@Html.AntiForgeryToken()
@Html.HiddenFor(m => m.ArticleID)
@Html.TextAreaFor(m => m.Text, new { @class = "form-control wide", @placeholder = "Type your comment", @rows = "3" })
@Html.ValidationMessageFor(m => m.Text, "", new { @class = "text-danger" })
}
这是控制器的操作:
[Authorize]
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Create([Bind(Include = "Text, ArticleID")] Comment comment){
if (comment == null || comment.ArticleID <= 0)
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
if (ModelState.IsValid){
comment.Date = DateTime.Now;
comment.UserID = User.Identity.GetUserId();
_commentRepository.Add(comment);
_commentRepository.Save();
}
return RedirectToAction("Details", "News", new { ID = comment.ArticleID });
}
由于正在采取行动的授权,如果用户没有在
[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public async Task<ActionResult> Login(LoginViewModel model, string returnUrl){
if (ModelState.IsValid){
var user = await UserManager.FindAsync(model.UserName, model.Password);
if (user != null){
await SignInAsync(user, model.RememberMe);
return RedirectToLocal(returnUrl);
}
else{
ModelState.AddModelError("", "Invalid username or password.");
}
}
return View(model);
}
记录
重定向URL将被评论/创建和将失败,一个404错误,确实存在管理这个问题的通用解决方案,因为我不能用一个简单的重定向操作?
工作时,您所提交的表单目标行动是不是调用它给404没有找到? – 2014-09-26 11:04:46
@Kartikeya我已经更新了错误 – InferOn 2014-09-26 11:17:20
而不是'return RedirectToLocal(returnUrl);'try'return RedirectToAction(“Create”,“Comments”);' – 2014-09-26 11:21:54