使用Microsoft.Reporting. WebForms中ReportViewer报表查看器(Server方式)

2023-11-17

添加Web Reference: http://<ReportServerName>/reportserver/reportexecution2005.asmx<?xml:namespace prefix = o />

 

login

        Message.Text = "";

 

        MyReportingService svc = new MyReportingService();

 

        //设置Web Service 的基URL

        svc.Url = "http://<ReportServerName>/reportserver/reportexecution2005.asmx";

        try

        {

            //登录WebService

            //svc.LogonUser(Username.Text, Password.Text, "Kerberos");

            svc.LogonUser(Username.Text, Password.Text, null);

            Cookie myAuthCookie = svc.AuthCookie;

 

            //如果登录后cookie为空,则登陆失败

            if (myAuthCookie == null)

            {

                Message.Text = "Logon failed";

            }

            //如果登录成功,页面转向ReturnUrl,并添加登录cookie

            else

            {

                HttpCookie cookie = new HttpCookie(myAuthCookie.Name,

 myAuthCookie.Value);

                Response.Cookies.Add(cookie);

                string returnUrl = Request.QueryString["ReturnUrl"];

                if (returnUrl == null || !returnUrl.StartsWith("/"))

                    Message.Text = "Return url is missing or invalid!";

                else

                    Response.Redirect(HttpUtility.UrlDecode(returnUrl));

            }

        }

        catch (Exception ex)

        {

            Message.Text = "Logon failed: " + ex.Message;

        }

MyReportingService:

using ReportExecution2005;

 

/// <summary>

/// ReportExecutionService的扩展代理类,

/// </summary>

public class MyReportingService : ReportExecutionService

{

    private Cookie m_authCookie;

 

    public Cookie AuthCookie

    {

        get

        {

            return m_authCookie;

        }

    }

 

    protected override WebRequest GetWebRequest(Uri uri)

    {

        HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(uri);

        request.Credentials = base.Credentials;

        request.CookieContainer = new CookieContainer();

        if (m_authCookie != null)

            request.CookieContainer.Add(m_authCookie);

        return request;

    }

 

    protected override WebResponse GetWebResponse(WebRequest request)

    {

        WebResponse response = base.GetWebResponse(request);

        string cookieName = response.Headers["RSAuthenticationHeader"];

        if (cookieName != null)

        {

            HttpWebResponse webResponse = (HttpWebResponse)response;

            m_authCookie = webResponse.Cookies[cookieName];

        }

        return response;

    }

}

ReportViewDemo:

using System.Web.SessionState;

using System.Security.Principal;

using Microsoft.Reporting.WebForms;

 

/// <summary>

/// 继承IRequiresSessionState,指定目标HTTP处理程序对会话状态具有访问权

/// </summary>

public partial class ReportViewDemo : Page, IRequiresSessionState

{

   

    void Page_Load(object sender, EventArgs e)

    {

        //读取Cookie

        HttpCookie cookie = Request.Cookies["sqlAuthCookie"];

        if (cookie == null)

        {

            string strUrl = "login.aspx?ReturnUrl=" + HttpUtility.UrlEncode(Request.RawUrl);

            Response.Redirect(strUrl);

        }

        else

        {

            reportViewer.ProcessingMode = ProcessingMode.Remote;

            reportViewer.ServerReport.ReportServerUrl = new Uri("http://<ServerName>/reportserver");

            reportViewer.ServerReport.ReportPath = "/ReportProject1/Report1";

 

            //System.Net.Cookie

            Cookie authCookie = new Cookie(cookie.Name, cookie.Value);

            authCookie.Domain = "localhost";

 

            //报表凭据验证

            reportViewer.ServerReport.ReportServerCredentials = new MyReportServerCredentials(authCookie);

          

        }

    }

}

MyReportServerCredentials :

class MyReportServerCredentials : IReportServerCredentials

{

    private Cookie m_authCookie;

 

    public MyReportServerCredentials(Cookie authCookie)

    {

        m_authCookie = authCookie;

    }

 

    public WindowsIdentity ImpersonationUser

    {

        get

        {

            return null// Use default identity.

        }

    }

 

    //Window集成验证方式

    public ICredentials NetworkCredentials

    {

        get

        {

            //return null;  // Not using NetworkCredentials to authenticate.

            return new System.Net.NetworkCredential("username", "password");

        }

    }

 

    //Form认证

    public bool GetFormsCredentials(out Cookie authCookie,

        out string user, out string password, out string authority)

    {

        //设置返回的cookie

        authCookie = m_authCookie;

        user = password = authority = null;

        return true// Use forms credentials to authenticate.

    }

}

转载于:https://www.cnblogs.com/caoxch/archive/2006/11/12/558277.html

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

使用Microsoft.Reporting. WebForms中ReportViewer报表查看器(Server方式) 的相关文章

  • Zabbix监控MariaDB服务

    文章目录 1 概述监控MariaDB服务主机 2 安装MariaDB服务和配置MariaDB 3 配置Zabbix的userparameter mysql conf 文件模板 4 在Web配置模板 5 在server进行压力测试mysql服
  • svg实现文本的垂直居中对齐样式

    项目中用到表格内画折线趋势图 本人使用的svg绘制简单折线 没有数据的单元格显示文字 为了不影响表格的宽度自适应 就想到在svg上写文字 于是就有了在svg上对文字样式进行垂直居中的需求 上代码
  • Linux教程:在虚拟机中如何配置Linux系统网络环境 ?

    对于很多初学Linux 的同学 大多选择使用虚拟机来展开学习 可以方便的做实验 修改 测试 不必害怕出问题 可以随便折腾 大不了换一个虚拟机 原来的系统不受任何影响 但由于不是实体pc机 使用难免受限 如果配置不好 后期开发必受其累 比如
  • C++Primer(4-8章)

    第四章 表达式 求值顺序 C 中没有明确规定大多数运算符的求值顺序 因此我们要避免 改变了某个运算对象的值 又在表达式其他地方使用这个运算对象 这种情况出现 赋值运算满足右结合律 在输出表达式中使用条件运算符 条件运算符的优先级非常低 因此
  • java修改AD域用户密码使用SSL连接方式

    正常情况下 JAVA修改AD域用户属性 只能修改一些普通属性 如果要修改AD域用户密码和userAccountControl属性就得使用SSL连接的方式修改 SSL连接的方式需要操作以下步骤 1 安装AD域证书服务 2 证书颁发机构中设置以
  • 【C语言】结构体中的函数指针

    目录 一 函数指针是什么 二 结构体中的函数指针 一 函数指针是什么 函数指针是指向函数的指针变量 通常我们说的指针变量是指向一个整型 字符型或数组等变量 而函数指针是指向函数 函数指针可以像一般函数一样 用于调用函数 传递参数 正确形式
  • 2.【Python】分类算法—Logistic Regression

    2 Python 分类算法 Logistic Regression 文章目录 2 Python 分类算法 Logistic Regression 前言 一 Logistic Regression模型 1 线性可分和线性不可分 2 Logis
  • 二.全局定位--开源定位框架livox-relocalization实录数据集测试

    相关博客 二十五 SLAM中Mapping和Localization区别和思考 goldqiu的博客 CSDN博客 二十五 SLAM中Mapping和Localization区别和思考 goldqiu的博客 CSDN博客 基于固态雷达的全局
  • 【Flink系列】- RocksDB增量模式checkpoint大小持续增长的问题及解决

    背景 Flink版本 1 13 5 一个使用FlinkSQL开发的生产线上任务 使用Tumble Window做聚和统计 并且配置table exec state ttl为7200000 设置checkpoint周期为5分钟 使用rocks
  • cr2格式缩略图不显示_苹果HEIC格式照片如何快速在windows电脑上查看

    相信很多人一定遇到这样的一个情况 出去旅游玩了一阵 辛辛苦苦回来将iphone拍的照片拷贝到windows电脑 windows7系统 上 想寻找一些心仪的照片 却发现是如下的样子 OMG 欺负我买不起苹果电脑是吧 我拍的是啥 什么也看不到
  • Linux —— XShell6远程操控开机、重启和用户登录注销

    1 关机 重启命令 shutdown h now 表示立即关机 shutdown h 1 表示一分钟后关机 shutdown r now 表示立即重启 halt 直接使用 等价于关机 reboot 就是重启系统 sync 把内存的数据同步到
  • 会议OA项目----我的审批

    前言 上一篇博客我将我的会议的送审和会议排座这两个功能完成 送审之后就到了审批阶段 那么这次做的就是 我的审批 一 实现思路 根据产品原型图 见产品原型图 我的审批界面与我的会议界面大同小异 那么我们可以调用之前的写好的SQL语句 只不过将
  • 文件上传/下载接口(超简单的教程来了)

    前言 文件上传 下载接口与普通接口类似 但是有细微的区别 如果需要发送文件到服务器 例如 上传文档 图片 视频等 就需要发送二进制数据 上传文件一般使用的都是 Content Type multipart form data 数据类型 可以
  • java懒加载注解_一分钟学习Spring注解之懒加载@Lazy

    先声明 本篇文章非常简单属于一分钟学会使用系列 不深入讲解原理 如果要学习源码 可以看小编Spring源码解析系列 什么是懒加载 懒加载就是不使用不加载 使用的时候才去加载 Spring默认不是懒加载 而是启动加载 就在Spring上下文启
  • rac集群节点级联重启故障分析

    author skate time 2012 07 16 无意中发现以前处理故障写的一篇文章 记录下来以备查找 rac集群节点级联重启故障分析 环境 os linux db rac10g ocfs2 rac数据库环境实际包含两个集群 一个是
  • linux socket非阻塞之connect 函数

    1 connect原型 include
  • 联想E480安装MacOS苹果系统记录

    联想E480安装MacOS记录 联想E480安装黑苹果 自己有用IPad和Iphone 但Mac OS却没怎接触过 于是萌生了转用Mac OS的想法 用自用的联想E480装个黑果 为了方便软件上的互补 双系统优先 网上搜搜转转没发现有E48
  • 代码随想录算法训练营第三天 | 203.移除链表元素、707.设计链表、206.反转链表

    目录 知识点 链表 结点定义 单链表的初始化 判断一个链表是否为空 单链表的销毁 清空单链表 求链表表长 取单链表中第i个元素 按值查找 插入第i个结点 删除第i个结点 移除列表元素 没有采用虚拟头结点的方法 采用虚拟头结点的方法 设计链表
  • PHPExcel导出各种方法总结

    PHPExcel导出 方法一 https blog csdn net u014236259 article details 60601767 public function ExportExcelOrder data name vendor
  • ARM+Linux中断系统详细分析

    ULK第四章里明确讲到 Linux实现了一种没有优先级的中断模型 并且 Linux中断和异常都支持嵌套 这个我不太理解了 这两种说法都与我以前的理解刚好相反 核对了原书 翻译没有错 Linux中断系统到底是否支持优先级 可否嵌套 中断号又是

随机推荐