![](/img/trans.png)
[英]How to Redirect to Last Visited page After Login in Asp.net core mvc
[英]Redirect to same page after Login in Asp.net core mvc
我想在登錄后重定向到同一頁面。
登錄.cshtml
@using (Html.BeginForm("Login", "Account", FormMethod.Post, new { returnUrl = Request.RawUrl }))
登錄 Controller
public ActionResult login(string returnUrl)
{
//If login successful
return Redirect(returnUrl);
}
我已經這樣做了,但它不起作用並在 Request.rawurl 中給出錯誤,因為它在 .net 核心 mvc 中不支持,並且它在 post 方法中給出了 returnUrl 值 null。 請幫助我正確的解決方案
您可以使用以下代碼。
<form asp-controller="xxx" asp-action="Login" asp-route-returnUrl="@Context.Request.Host@Context.Request.Path" method="post">
//...
<input type="submit" value="test" />
</form>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.