Sam*_*m M 8 c# sql-server reporting-services ssrs-2008 asp.net-mvc-3
我的应用是在 Asp.Net MVC3
编码中C#
,我有一个SSRS解决方案SQL Server Business Intelligence Developement Studio
中Visual Studio 2008
,我打电话SSRS通过我的报告Asp.Net MVC3应用.几天前我的应用程序运行正常,但突然我收到如下错误:
我的错误:
The request failed with HTTP status 401: Unauthorized.
Run Code Online (Sandbox Code Playgroud)
我的尝试
我的SSRS报告部署在我的local server
.我在SSRS报告解决方案的数据源中正确设置了我的凭证.
我试图在我的web.config中添加标签 <identity impersonate="true" userName="Domain\username" password="Password" />
我尝试添加 IReportServerCredentials reportCredentials = new ReportServerCredentials("MyUserName", "MyPassword", "ServerName");
我运行Visual Studio作为'Run as Administrator'
.
我尝试了此链接中提到的解决方案使用RegEdit创建密钥
更新 我尝试了以下解决方案,但结果相同:SSRS中的未经授权的错误
以上解决方案都没有奏效,但是当我在其他机器上运行相同的解决方案时,解决方案运行良好并且没有显示错误.它只有当我从我的机器运行解决方案然后我得到错误The request failed with HTTP status 401: Unauthorized.
我也遇到同样的错误,
The request failed with HTTP status 401: Unauthorized.
Run Code Online (Sandbox Code Playgroud)
让我分享一下我尝试过的方法,现在效果很好。
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;
}
}
Run Code Online (Sandbox Code Playgroud)
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();
}
Run Code Online (Sandbox Code Playgroud)
这对我有用!
尝试这个
public void GetConnectionOfReportServer()
{
try
{
NetworkCredential credential = new NetworkCredential("administrator", "password@123", "Domain");
this.reportViewer1.ServerReport.ReportServerCredentials.NetworkCredentials = credential;
//select where the report should be generated with the report viewer control or on the report server using the SSRS service.
this.reportViewer1.ProcessingMode = Microsoft.Reporting.WinForms.ProcessingMode.Local;
this.reportViewer1.ServerReport.ReportServerUrl = new Uri(@"http://localhost/ReportServer");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
36252 次 |
最近记录: |