這取決於框架。例如,在ASP.NET MVC中,當框架檢測到用戶正在嘗試訪問受保護資源時,它將用戶重定向到具有受保護資源URL的登錄頁面作爲查詢字符串參數。
成功驗證後,它將查詢字符串中的URL並將其重定向到那裏。
編輯 在重定向之前檢查重定向URL總是一個好主意。 ASP.NET MVC確保返回URL是本地URL。這裏是如何在ASP.NET MVC中實現的。
public async Task<ActionResult> Login(LoginViewModel model, string returnUrl)
{
if (ModelState.IsValid)
{
// Validate the user password
if (await Secrets.Validate(model.UserName, model.Password))
{
string userId = await Logins.GetUserId(IdentityConfig.LocalLoginProvider, model.UserName);
await SignIn(userId, model.RememberMe);
return RedirectToLocal(returnUrl);
}
}
// If we got this far, something failed, redisplay form
ModelState.AddModelError(String.Empty, "The user name or password provided is incorrect.");
return View(model);
}
private ActionResult RedirectToLocal(string returnUrl)
{
if (Url.IsLocalUrl(returnUrl))
{
return Redirect(returnUrl);
}
else
{
return RedirectToAction("Index", "Home");
}
}
[WS-Federation](http://en.wikipedia.org/wiki/WS-Federation)也許? – rene
人,當你投票時,給他們一個理由。所以他們從中吸取教訓。 – iraSenthil
可能是更好的修復程序員.stackexchange.com –