【问题标题】:'Response' does not contain a definition for 'Redirect'“响应”不包含“重定向”的定义
【发布时间】:2019-07-18 16:37:46
【问题描述】:

我正在尝试使用 AspNetSaml nuget 包 (https://github.com/jitbit/AspNetSaml),但在尝试使用 Response.Redirect(url) 方法时出现错误。

这是错误:

错误 CS0117“响应”不包含“重定向”的定义

我已经在使用命名空间 System.Web 并且还添加了 System.Web.dll

static void Redir(Response samlResponse)
{
    //specify the SAML provider url here, aka "Endpoint"
    var samlEndpoint = "https://saml.xxxx.com/idp/SSO.saml2";

    AuthRequest request = new AuthRequest(
        "https://www.xxxx.com/", //put your app's "unique ID" here
        "https://www.xxxx.com/" //assertion Consumer Url - the redirect URL where the provider will send authenticated users
        );

    // Generate the provider URL
    string url = request.GetRedirectUrl(samlEndpoint);

    Response.Redirect(url);
}

【问题讨论】:

    标签: c# .net saml system.web


    【解决方案1】:

    您似乎正试图从静态方法访问页面的HttpResponse 对象。使您的方法非静态:

    void Redir(Response samlResponse)
    {
        ...
        this.Response.Redirect(url);
    }
    

    【讨论】:

      【解决方案2】:

      你可以替换你的函数调用

      Redire(this.Response)
      

      通过

      Response.Redirect(Redire())
      

      使用您的 Redire 函数返回要重定向到的 url。这样您就可以摆脱造成问题的静态上下文。

      【讨论】:

        猜你喜欢
        • 2015-03-03
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-01-27
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多