如何在ASP.Net Core Razor页面上重定向 [英] How to redirect on ASP.Net Core Razor Pages
本文介绍了如何在ASP.Net Core Razor页面上重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在ASP.Net core 2中使用新的Razor Pages
现在我需要重定向
I am using the new Razor Pages in ASP.Net core 2
Now I need to redirect
我尝试了此操作,但页面未重定向:
I tried this, but the page does not redirect:
public class IndexModel : PageModel
{
public void OnGet()
{
string url = "/.auth/login/aad?post_login_redirect_url=" + Request.Query["redirect_url"];
Redirect(url);
}
}
如何重定向?
推荐答案
您非常亲密.这些方法需要返回IActionResult
(对于异步方法,则为Task<IActionResult>
),然后您需要返回重定向.
You were very close. These methods need to return an IActionResult
(or Task<IActionResult>
for async methods) and then you need to return the redirect.
public IActionResult OnGet()
{
string url = "/.auth/login/aad?post_login_redirect_url="
+ Request.Query["redirect_url"];
return Redirect(url);
}
但是,您有一个庞大的打开重定向攻击,因为您没有验证redirect_url
变量. 请勿在生产环境中使用此代码.
However, you have a huge Open Redirect Attack because you aren't validating the redirect_url
variable. Don't use this code in production.
这篇关于如何在ASP.Net Core Razor页面上重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文