繁体   English   中英

当我使用 asmx 服务和 SSRS 报告服务时,我收到“请求失败,http 状态为 401:未经授权”

[英]when I use asmx service and SSRS report service I am getting "The request failed with http status 401: unauthorised"

我试图通过在本地运行来从我的 asp.net Web 应用程序调用报告相关服务 (asmx)。 然后发生了一个异常说。 The request failed with http status401:unauthorised

在我的分析中,我理解了由以下代码引起的问题

SSRSWebService.ReportingService2005 rs = new SSRSWebService.ReportingService2005();
rs.Credentials = new MyReportServerCredentials().NetworkCredentials;

Uri reportUri = new Uri(ConfigurationManager.AppSettings["ReportServerManagement.ReportingService2005"]);
this.rptViewer.ServerReport.ReportServerCredentials = new MyReportServerCredentials();

在我的详细分析中,我了解到问题是因为在serviceObject.credentialServerReport.ReportServerCredentials 中设置的凭据是错误的。 这可以通过两种不同的方式来纠正,方法是使用以下代码将凭据设置为默认值

rs.Credentials = System.Net.CredentialCache.DefaultCredentials;//"rs" is report object

或者找到下面的代码并在代码中设置适当的经过身份验证的用户凭据

 public WindowsIdentity ImpersonationUser
{
    get
    {
        // Use the default Windows user.  Credentials will be
        // provided by the NetworkCredentials property.
        return null;
    }
}

public ICredentials NetworkCredentials
{
    get
    {
        // Read the user information from the Web.config file.  
        // By reading the information on demand instead of 
        // storing it, the credentials will not be stored in 
        // session, reducing the vulnerable surface area to the
        // Web.config file, which can be secured with an ACL.

        // User name
        string userName =
            <<AccurateUserName;>>


        // Password
        string password =
            <<AccuratePassword;>>

        // Domain
        string domain = <<AccurateDomainName;>>


        return new NetworkCredential(userName, password, domain);
    }
}

为了检查哪个用户具有访问权限,我们需要在 Web 浏览器中键入以 asmx ( http:/MyServiceHostedServer/MyService.asmx ) 结尾的服务 URL。 它会提示用户名和密码。 提供我们的用户名:域\\用户名和密码。如果我们能够看到 wsdl xml 文件,那么该用户具有访问权限。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM