[英]Redirect(url) not redirecting
I have a simple login screen in .Net MVC. 我在.Net MVC中有一个简单的登录屏幕。 I use Redirect()
method to redirect to the given url after succesful login, but Redirect(url)
does not get anywhere, the page remains in the login screen. 我在成功登录后使用Redirect()
方法重定向到给定的URL,但Redirect(url)
无法到达任何地方,页面仍保留在登录屏幕中。
Below link gets returnurl
fine: @Html.ActionLink("Buy","Login","Account",new { returnUrl = Request.RawUrl })
以下链接returnurl
正常: @Html.ActionLink("Buy","Login","Account",new { returnUrl = Request.RawUrl })
Then in the login screen, returnUrl shows this url: http://localhost:1820/Account/Login?returnUrl=%2FBasket%2FGoToShopCart
然后在登录界面中,returnUrl显示此URL: http://localhost:1820/Account/Login?returnUrl=%2FBasket%2FGoToShopCart
Redirect(url) which is not redirecting: 重定向(url)不重定向:
[HttpPost]
public ActionResult Login(Login l, string returnurl)
{
RegisteredCustomer rc = new RegisteredCustomer();
string url = "";
Repository r = new Repository();
var obj = r.GetUser(l);
if (obj != null)
{
Session["UserID"] = obj.RegisterID.ToString();
url = returnurl;
}
else
url ="/Account/Login";
return Redirect(url);
}`
And I pass url to HttpPost method here in login View: 我在登录视图中将url传递给HttpPost方法:
`@using (Html.BeginForm("Login", "Account", new { returnUrl = Request.QueryString["ReturnUrl"] }, FormMethod.Post))
{
@Html.Hidden("returnUrl", ViewContext.HttpContext.Request.Url.PathAndQuery)
@Html.AntiForgeryToken()
@Html.ValidationSummary(true)
...
<input type="submit" value="Enter" />
}` }`
Also it is not redirecting this url neither : 此外,它不会重定向此网址:
http://localhost:1820/Account/Login
I have checked these answers but couldn't help me: 我检查了这些答案,但无法帮助我:
Redirect to returnURL not working Redirect request to 'ReturnUrl' displays Login Page 重定向到returnURL不工作 重定向请求到'ReturnUrl'显示登录页面
您可以使用return RedirectToAction(“Login”,“Account”);
As I can see the url needs to be properly constructed. 我可以看到网址需要正确构建。 The answer from @NKosi at https://stackoverflow.com/a/44837491/5770686 I belive can help you, and also using other Redirect methods like RedirectToAction, RedirectToRoute etc. ( https://docs.microsoft.com/en-us/dotnet/api/system.web.mvc.controller.redirect?view=aspnet-mvc-5.2 ) 来自@NKosi的回复https://stackoverflow.com/a/44837491/5770686我相信可以帮助您,也可以使用其他Redirect方法,如RedirectToAction,RedirectToRoute等。( https://docs.microsoft.com/en- us / dotnet / api / system.web.mvc.controller.redirect?view = aspnet-mvc-5.2 )
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.