c# - 请求失败,HTTP 状态为 401 : Unauthorized IN SSRS

标签 c# sql-server asp.net-mvc-3 reporting-services ssrs-2008

我的申请在 Asp.Net MVC3编码为 C# ,我在 SQL Server Business Intelligence Developement Studio 中有一个 SSRS 解决方案在Visual Studio 2008 ,我正在通过我的 Asp.Net MVC3 应用程序调用 SSRS 报告。几天前我的应用程序运行良好,但突然出现如下错误:

我的错误:

The request failed with HTTP status 401: Unauthorized.

我的尝试

  1. 我的 SSRS 报告部署在我的 local server 上.我在 SSRS 报告解决方案的数据源中正确设置了我的凭据。

  2. 我试图在我的 web.config 中添加标签 <identity impersonate="true" userName="Domain\username" password="Password" />

  3. 我尝试添加 IReportServerCredentials reportCredentials = new ReportServerCredentials("MyUserName", "MyPassword", "ServerName");

  4. 我以 'Run as Administrator' 运行 Visual Studio .

  5. 我尝试了此链接中提到的解决方案 Creating a key using RegEdit

  6. 更新 我也尝试了以下解决方案,但结果相同:Unauthorized error in SSRS

以上解决方案均无效,但当我在其他机器上运行相同的解决方案时,这些解决方案运行良好且未显示任何错误。只有当我从我的机器运行解决方案时,我才会收到错误 The request failed with HTTP status 401: Unauthorized.

最佳答案

同样的错误,

The request failed with HTTP status 401: Unauthorized.

让我分享一下我的尝试,它现在运行良好。

public class CustomSSRSCredentials : IReportServerCredentials
    {
        private string _SSRSUserName;
        private string _SSRSPassWord;
        private string _DomainName;

        public CustomSSRSCredentials(string UserName, string PassWord, string DomainName)
        {
            _SSRSUserName = UserName;
            _SSRSPassWord = PassWord;
            _DomainName = DomainName;
        }

        public System.Security.Principal.WindowsIdentity ImpersonationUser
        {
            get { return null; }
        }

        public ICredentials NetworkCredentials
        {
            get { return new NetworkCredential(_SSRSUserName, _SSRSPassWord, _DomainName); }
        }

        public bool GetFormsCredentials(out Cookie authCookie, out string user,
         out string password, out string authority)
        {
            authCookie = null;
            user = password = authority = null;
            return false;
        }
    }

page_load 事件中,

if (!Page.IsPostBack)
{
    ReportViewer1.ProcessingMode = ProcessingMode.Remote;
    IReportServerCredentials ssrscredentials = new CustomSSRSCredentials("MyUserName", "MyPassword", "ServerName");
    ServerReport serverReport = ReportViewer1.ServerReport;
    ReportViewer1.ServerReport.ReportServerCredentials = ssrscredentials;
    serverReport.ReportServerUrl = new Uri("ReportPathKey");
    serverReport.ReportPath = "/Reports/MyReport";
    serverReport.Refresh();
}

这对我有用!

关于c# - 请求失败,HTTP 状态为 401 : Unauthorized IN SSRS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19247645/

相关文章:

c# - DisplayFor 辅助方法呈现实体的 ID,但不会将其沿着 POST 表单集合传递

c# - 在 documentDB 中按子字符串搜索

asp.net - 如何根据另一列的值获取一列的最大值?

c# - 奇怪的是 SQL Server Management Studio 中的数据

javascript - 为什么 jquery-ui 对话框的高度总是设置为 auto?

asp.net-mvc-3 - MVC 模型在 OnExecuted 操作过滤器中为空……还是设置模型的更优雅的方式?

c# - 多线程环境中的静态方法

c# - 如何在 C# 中检查 Excel 范围是否为空

c# - "Unable to cast object of type ' System.Net.Http.Formatting.JsonContractResolver ' to type ' Newtonsoft.Json.Serialization.DefaultContractResolver '."

c# - 如何登录 Entity Framework Core UseSqlServer 重试