我正在ASP中使用新的Razor页面.净核心2

我try 了这个,但页面没有重定向:

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>),然后您需要返回重定向.

public IActionResult OnGet()
{
    string url = "/.auth/login/aad?post_login_redirect_url=" 
      + Request.Query["redirect_url"];

    return Redirect(url);
}

Razor pages documentation

然而,你有一个巨大的Open Redirect Attack,因为你没有验证redirect_url变量.Don't use this code in production

Asp.net相关问答推荐

ASP.NET MVC项目中的产品采购并发性测试

Razor 页面客户端站点验证不起作用

使用 Asp.Net MVC 和 KnockoutJS 处理日期

如何正确配置 IHttpModule?

在 aspx 页面中使用 if else 和 eval

在正则表达式中允许 -(破折号)

如何使用特定视图(不是控制器名称)返回 ActionResult

返回 HttpResponseMessage 时的 WebAPI Gzip

在控制器 asp.net mvc 5 的视图上显示错误消息

如何在 ASP.NET Web API 中使用非线程安全的 async/await API 和模式?

asp.net 中的 Eval() 有什么用

Web Api 参数始终为空

温莎城堡有什么缺点吗?

IIS 10 上的 ASP.NET Core 404 错误

使用 LINQ 进行递归控制搜索

您如何在 .net WebApi2 应用程序中的 OAuth2 令牌请求中使用额外参数

如何在不预编译的情况下使用命令行msbuild部署VS2012网站项目?

通过 ASP.NET/C# 使用 Plupload

HttpResponse.End 或 HttpResponse.Close 与 HttpResponse.SuppressContent

将字典绑定到中继器