Authentication “的价值在哪里?”;returnUrl";在MVC5中设置?它总是带我去/家/索引
在运行时,无论我在哪里找到它,它都是空的 我已经得到了MVC5模板对2013的所有支持。 我找到了所有额外的标识和数据注释,一切都正常。(40个文件和5个表格,稍后见sheez) 但当登录时,所有操作都会完成,但注册用户会被重定向到“主页/索引”页面,即模板附带的默认页面。我想让他们去别的地方,比如“PickLocation” 现在,在我的代码中找不到通过搜索整个解决方案引用的“/Home/Index”。在Web.config中,身份验证模式设置为“无” 这是我在_LoginPartial.cshtml中的注册链接: 在my AccountController中,登录ActionResult为“returnURL”参数返回“null”。在成功时(这就是发生的情况),它会转到“return RedirectToLocal(returnUrl);”这个集合在哪里?我在任何地方都找不到returnURL的值,也找不到它的设置位置,我不想继续出现在模板附带的MS默认主页/索引页上。注销也会转到主页/索引页。我将IIS默认页面设置为“PickLocation.cshtml”,但运气不好 以下是登录操作代码: 以下是AccountController登录获取“方法”Authentication “的价值在哪里?”;returnUrl";在MVC5中设置?它总是带我去/家/索引,authentication,asp.net-mvc-5,Authentication,Asp.net Mvc 5,在运行时,无论我在哪里找到它,它都是空的 我已经得到了MVC5模板对2013的所有支持。 我找到了所有额外的标识和数据注释,一切都正常。(40个文件和5个表格,稍后见sheez) 但当登录时,所有操作都会完成,但注册用户会被重定向到“主页/索引”页面,即模板附带的默认页面。我想让他们去别的地方,比如“PickLocation” 现在,在我的代码中找不到通过搜索整个解决方案引用的“/Home/Index”。在Web.config中,身份验证模式设置为“无” 这是我在_LoginPartial.cs
但问题仍然存在:“项目/解决方案在注册或注销后返回给我的“/home/index”究竟在哪里?没有“/home/index”在搜索中出现在哪里。噢,天哪,如果是蛇,它会咬我的。 我在搜索“主页/索引”。我没想到它会像“Action,Controller”那样独立。sheez 我在我的项目中搜索“private Action Result RedirectToLocal”,我得到了这个动作,在底部是“return RedirectToAction(“索引”,“主页”);“我很确定我可以在那里改变。我希望我的痛苦能帮助像我这样的新手。”
private ActionResult RedirectToLocal(string returnUrl)
{
if (Url.IsLocalUrl(returnUrl))
{
return Redirect(returnUrl);
}
return RedirectToAction("Index", "Home");
}
链接应该是
routeValues:new{returnUrl=ViewBag.returnUrl}
假设您在Login
GET方法中设置了值-您没有显示代码,所以不确定您做了什么。但是您显示的链接是针对Register()
方法的,但是您显示了Login()
方法的代码
public class HomeController : Controller
{
public ActionResult Index()
{
ViewBag.Notice = "This is coming from Home Controller";
return View();
}
public async Task<ActionResult> Login(LoginViewModel model, string returnUrl)
{
if (!ModelState.IsValid)
{
return View(model);
}
// This doesn't count login failures towards account lockout
// To enable password failures to trigger account lockout, change to shouldLockout: true
var result = await SignInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, shouldLockout: false);
switch (result)
{
case SignInStatus.Success:
return RedirectToLocal(returnUrl);
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
//routes.MapRoute(
// name: "Default",
// url: "{controller}/{action}/{id}",
// defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
//);
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Stores", action = "PickLocation", id = UrlParameter.Optional }
);
}
// GET: /Account/Login
[AllowAnonymous]
public ActionResult Login(string returnUrl)
{
ViewBag.ReturnUrl = returnUrl;
return View();
}
private ActionResult RedirectToLocal(string returnUrl)
{
if (Url.IsLocalUrl(returnUrl))
{
return Redirect(returnUrl);
}
return RedirectToAction("Index", "Home");
}