在運行時我發現它處處都是空的。MVC 5中設置「returnUrl」的值在哪裏?它總是把我帶到/首頁/索引
我已經得到了所有與MVC 5模板VS 2013一起來的花裏胡哨。 我想出了所有額外的Indentity和DataAnnotations的東西,它的一切工作。 (40個文件和5個表格後sheez)。
但是,在登錄時,所有內容都會經過,但註冊用戶會被重定向到「Home/Index」頁面,即模板附帶的默認頁面。我希望他們能夠到別的地方,比如「PickLocation」。
現在在我的代碼中無處可找到通過搜索整個解決方案引用的「/ Home/Index」。在Web.config中,身份驗證模式設置爲「無」。
這裏是_LoginPartial.cshtml我的註冊鏈接:
<li>@Html.ActionLink("Register", "Register", "Account", routeValues: null, htmlAttributes: new { id = "registerLink", style = "color:white;" })</li>
不知怎的,它負責爲HomeController的。 這裏是家庭控制器的ActionResult,我可以把一個斷點來證明這一點被擊中:
public class HomeController : Controller
{
public ActionResult Index()
{
ViewBag.Notice = "This is coming from Home Controller";
return View();
}
在我的AccountController登錄的ActionResult返回「空」爲「RETURNURL」參數。在成功(這是發生了什麼)它會轉到「返回RedirectToLocal(returnUrl);」這個集合在哪裏?我無處可以找到returnURL的價值或設置它的位置,我不想繼續最終在模板附帶的MS默認主頁/索引頁面上。註銷也進入Home/Index頁面。我設置IIS默認頁面爲「PickLocation.cshtml」,但沒有運氣
這裏是登錄操作代碼在這裏:
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);
編輯: 我只記得有人會問,如果這是在RouteConfig.cs中設置。 .. 。不,這不對。
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 }
);
}
這裏是的AccountController登錄GET「方法」
// GET: /Account/Login
[AllowAnonymous]
public ActionResult Login(string returnUrl)
{
ViewBag.ReturnUrl = returnUrl;
return View();
}
但問題依然存在:「在到底哪裏是項目/解決方案獲得‘/首頁/指數’,它發送回去後註冊或註銷?沒有「/ home/index」在搜索中顯示的位置。
鏈接應該是'routeValues:新{RETURNURL = ViewBag.ReturnUrl}'假設你已經設置的'Login' GET方法的價值 - 你沒有顯示的代碼,所以不知道你做了什麼。但是你顯示的鏈接是一個'Register()'方法,但是你已經顯示了一個'Login()'方法的代碼 –