您的位置:首页 > 其它

SSRS 报表 如何匿名查看

2016-03-10 11:35 225 查看

SSRS 报表 如何匿名查看

昨晚一直研究怎么能匿名访问报表然后给客户看呢?

研究了好几种办法

我试过的分为三种,其中推荐我认为相对可控一点。

1.修改SSRS配置文件来禁止他验证登陆用户权限
 操作过的文章:SSRS匿名登录
 可以完全匿名访问,因为我们系统是涉及到客户要自己做报表的,所以这里屏蔽了权限问题,那么这种办法对我来说是不可行的。
2.修改IIS配置
 操作过的文章:匿名访问的一个间接方法
 这种办法和第三种类似但是这个是直接操作IIS的如果集成到系统中也不是很科学。


我用的是通过程序伪装登陆之后获得报表

我觉得这样的好处是,可以控制此账户只有浏览的权限,并不破坏任何东西

需要做的就是两点:

1.前台还是一样,一个ScriptManager 一个ReportViewer

2.而后台代码这样写。其中把登陆用户名和账户都存到存到配置文件当中。请自行添加

3.这个类的介绍:https://msdn.microsoft.com/en-us/library/microsoft.reporting.webforms.ireportservercredentials.aspx

public partial class One : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
ReportParameter para = new ReportParameter("ReportParameter1", "1");
ReportViewer1.ServerReport.ReportServerCredentials = new MyReportServerCredentials();
ReportViewer1.ServerReport.ReportServerUrl = new Uri("http://报表服务器地址/reportserver");
ReportViewer1.ServerReport.ReportPath = "/报表地址";
ReportViewer1.ServerReport.SetParameters(new ReportParameter[] { para });
}

}

}
[Serializable]
public sealed class MyReportServerCredentials : IReportServerCredentials
{
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 =
ConfigurationManager.AppSettings
["myReportViewerUser"];

if (string.IsNullOrEmpty(userName))
throw new Exception(
"Missing user name from web.config file");

// Password
string password =
ConfigurationManager.AppSettings
["MyReportViewerPassword"];

if (string.IsNullOrEmpty(password))
throw new Exception(
"Missing password from web.config file");

// Domain
string domain =
ConfigurationManager.AppSettings
["MyReportViewerDomain"];

if (string.IsNullOrEmpty(domain))
throw new Exception(
"Missing domain from web.config file");

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

public bool GetFormsCredentials(out Cookie authCookie,
out string userName, out string password,
out string authority)
{
authCookie = null;
userName = null;
password = null;
authority = null;

// Not using form credentials
return false;
}
}


可以成功访问了。。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: