How to redirect on ASP.Net Core Razor Pages

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);
}

Razor pages documentation

However, you have a huge Open Redirect Attack because you aren’t validating the redirect_url variable. Don’t use this code in production.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)