mvc的sql reportviewer问题 [英] sql reportviewer problem with mvc

查看:122
本文介绍了mvc的sql reportviewer问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法使用reportviewer来处理作为MVC3项目一部分的aspx页面。

Reportviewer可以很好地连接到服务器并在需要时获取参数。但是body从不显示报告(或任何错误)并且导出按钮被禁用。



有趣的是,如果我在ASP中创建完全相同的页面(除了继承)。 NET项目它工作正常。

所以我的第一个想法是它与web.config设置有关,但即使从它删除任何对reportviewer的引用也不会停止报告从事ASP的工作它看起来像任何处理程序,httphandlers,构建提供程序和程序集都不是必需使它工作。(如果你看页面源它会抛出你的浏览器不支持脚本......和报表查看器Web控件HTTP处理程序有没有注册...废话恭候)



以下是来自web.config的相关内容

 < span class =code-keyword><   buildProviders  >  
< add extension = .rdlc type = Microsoft.Reporting.RdlBuildProvider,Microsoft.ReportViewer.WebForms,Version = 10.0.0.0,Culture = neutral,PublicKeyToken = b03f5f7f11d50a3a / >
< / buildProviders >



 <   system.webServer  >  
< validation validateIntegratedModeConfiguration = false / >
< 处理程序 >
< add 名称 = ReportViewerWebControlHandler preCondition = integratedMode 动词 = * path = 保留。 ReportViewerWebControl.axd type = Microsoft.Reporting.WebForms.HttpHandler,Microsoft.ReportViewer.WebForms,Version = 10.0.0.0,Culture = neutral,PublicKeyToken = b03f5f7f11d50a3a / >
< / handlers >
< / system.webServer >



 <   system.web  >  
< / pages >
< 编译 debug = true >
< assembly < span class =code-keyword>> < add 程序集 = Microsoft.ReportViewer.WebForms,Version = 10.0.0.0,Culture = neutral,PublicKeyToken = B03F5F7F11D50A3A / >
< / assemblies >



这是页面:

 < %@     Page    < span class =code-attribute>语言  =  C#   继承  =  System.Web.Mvc.ViewPage   %>  
<%@ 注册 程序集 = Microsoft.ReportViewer.WebForms,
Version = 10.0.0.0,Culture = neutral,
PublicKeyToken = b03f5f7f11d50a3a


namespace = Microsoft.Reporting.WebForms

tagprefix = rsweb %>
<%@ 导入 命名空间 < span class =code-attribute> = MvcMusicStore.Reports %>

< !DOCTYPE html PUBLIC - // W3C // DTD XHTML 1.0 Transitional // EN http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd >

< html xmlns = http://www.w3.org/1999/xhtml >
< head runat = 服务器 >
< title > < / title >
< / head >
< body > < /温泉n>

< script runat = server >

private void Page_Load( object sender,System.EventArgs e)
{
if (!IsPostBack)
{
string reportPath = < span class =code-string> / Reports / Management Reports / Stock Report
;

ReportServerConnection rsc = new ReportServerConnection();

this .ReportViewer1.ServerReport.ReportServerCredentials = rsc;
this .ReportViewer1.ServerReport.ReportPath = reportPath;
this .ReportViewer1.ServerReport.ReportServerUrl =
new Uri(( http:// MyServerName / ReportServer));


this .ReportViewer1.ServerReport.Refresh();
}
}

< / script >

< 表格 id = Form1 runat = server width = 800px height = 600px < span class =code-keyword>>
< ajaxToolkit:ToolkitScriptManager ID = ScriptManager1 < span class =code-attribute> runat = server EnablePageMethods = true EnableScriptGlobalization = true

< span class =code-attribute> EnableScriptLocalization = true >
< < span class =code-leadattribute> / ajaxToolkit:ToolkitScriptManager >
< asp:Panel ID < span class =code-keyword> = Panel2 runat = server 字体大小 = 12pt

GroupingText = 宽度 = 800px 高度 = 600px BorderColor = 红色 BorderWidth = 1 >
start
< rsweb:reportviewer ID = ReportViewer1 runat = server

SizeToReportContent = False 宽度 = 800px 高度 = 600px

ZoomMode = FullPage ProcessingMode = 远程 BackColor = 白色 AsyncRendering = true

BorderStyle = Solid < span class =code-attribute> 已启用 = true BorderColor = 绿色 BorderWidth = 1px > < / rsweb:reportviewer > 结束

< / asp:Panel >
< / form >

< < span class =code-leadattribute> / body >
< / html >



和连接class:

 使用系统; 
使用 System.Collections.Generic;
使用 System.Linq;
使用 System.Web;
使用 Microsoft.Reporting.WebForms;
使用 System.Net;
使用 System.Configuration;
使用 System.Security.Principal;

namespace MvcMusicStore.Reports
{
[Serializable]
public class ReportServerConnection:IReportServerConnection2
{
public Uri ReportServerUrl
{
get
{
string url = ConfigurationManager.AppSettings [ ReportViewerPath]; // http:// localhost / ReportServer
if string .IsNullOrEmpty(url))
throw new 异常( Web.config文件中缺少网址);
return new Uri(url);
}
}
public int 超时
{
// 将超时设置为60秒
获取 {返回 60000 ; }
}

public IEnumerable< Cookie> Cookie
{
// 无自定义Cookie
get { return null ; }
}
public IEnumerable< string>标头
{
// 无自定义标头
get { return null ; }
}

public GEMReportServerConnection()
{
}


public WindowsIdentity ImpersonationUser
{
get { return null ; }
}

public ICredentials NetworkCredentials
{
get
{
// return null将强制使用模拟,
// 否则,删除返回null和
// 实施其他应用设置以指定凭证详细信息
// 返回null;

string userName = ConfigurationManager.AppSettings [ ReportViewerUser];
if string .IsNullOrEmpty(userName))
throw new 异常( Web.config文件中缺少用户名);
string password = ConfigurationManager.AppSettings [ ReportViewerPassword];
if string .IsNullOrEmpty(password))
throw new 异常( Web.config文件中缺少密码);
string domain = ConfigurationManager.AppSettings [ ReportViewerDomain];
if string .IsNullOrEmpty(domain))
throw new 异常( Web.config文件中缺少域);
return new NetworkCredential(userName,password,domain);
}
}

public bool GetFormsCredentials(
out Cookie authCookie,
out string userName,
out string 密码,
out string 权限)
{
authCookie = ;
userName = null ;
password = null ;
authority = null ;
return false ;
}
}
}



我猜我的ajax:ToolkitScriptManager工作正常(有没有办法测试它? )。有什么想法吗?

解决方案

< asp:scriptmanager id =ScriptManager1runat =serverxmlns:asp =#unknown>

  EnablePartialRendering  =   false> 
< / asp:ScriptManager



>



http://social.msdn.microsoft.com/Forums/en-GB/vsreportcontrols/thread/6219309d-030d-4618-8580-4f534b7ba55d [ ^ ]


I can''t get reportviewer to work on aspx page that is part of MVC3 project.
Reportviewer connects fine to server and obtains parameters if needed. But body never shows the report (or any error) and export button is disabled.

Funny thing is that if I create exactly same page (besides inheritance) in ASP.NET project it works fine.
So my first thought was that it has something to do with web.config settings but even removing any references to reportviewer from it doesn''t stop report from working on ASP so it looks like any of the handlers,httphandlers,buildproviders and assemblies are not "required" to make it work.(if you look on page source it throws Your browser does not support scripts...and The Report Viewer Web Control HTTP Handler has not been registered... nonsense regardles)

Here are relevant lines from web.config

<buildProviders>
   <add extension=".rdlc" type="Microsoft.Reporting.RdlBuildProvider, Microsoft.ReportViewer.WebForms, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
</buildProviders>


<system.webServer>
    <validation validateIntegratedModeConfiguration="false" />
    <handlers>    
      <add name="ReportViewerWebControlHandler" preCondition="integratedMode" verb="*" path="Reserved.ReportViewerWebControl.axd" type="Microsoft.Reporting.WebForms.HttpHandler, Microsoft.ReportViewer.WebForms, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
    </handlers>
  </system.webServer>


<system.web>   
    </pages>
    <compilation debug="true">
      <assemblies><add assembly="Microsoft.ReportViewer.WebForms, Version=10.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A" />
      </assemblies>


Here is page:

<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage" %>
<%@ Register assembly="Microsoft.ReportViewer.WebForms, 
Version=10.0.0.0, Culture=neutral, 
PublicKeyToken=b03f5f7f11d50a3a" 

namespace="Microsoft.Reporting.WebForms" 

tagprefix="rsweb" %>
<%@ Import Namespace = "MvcMusicStore.Reports" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>

    <script runat="server">
      
            private void Page_Load(object sender, System.EventArgs e)
            {
                if (!IsPostBack)
                {
                    string reportPath = "/Reports/Management Reports/Stock Report";

                    ReportServerConnection rsc = new ReportServerConnection();

                    this.ReportViewer1.ServerReport.ReportServerCredentials = rsc;
                    this.ReportViewer1.ServerReport.ReportPath = reportPath;
                    this.ReportViewer1.ServerReport.ReportServerUrl =
                       new Uri(("http://MyServerName/ReportServer"));

                    
                        this.ReportViewer1.ServerReport.Refresh();
                } 
            }
            
        </script>
        
        <form id="Form1" runat="server" width="800px" height="600px">
        <ajaxToolkit:ToolkitScriptManager ID="ScriptManager1"  runat="server" EnablePageMethods="true" EnableScriptGlobalization="true"

                                EnableScriptLocalization="true">          
        </ajaxToolkit:ToolkitScriptManager>
        <asp:Panel ID="Panel2" runat="server" Font-Size="12pt" 

        GroupingText="" Width="800px" Height="600px" BorderColor="Red" BorderWidth="1">
        start
        <rsweb:reportviewer ID="ReportViewer1"  runat="server" 

    SizeToReportContent="False" Width="800px" Height="600px"

    ZoomMode="FullPage" ProcessingMode="Remote" BackColor="White" AsyncRendering="true"

                    BorderStyle="Solid" Enabled="true" BorderColor="Green" BorderWidth="1px"></rsweb:reportviewer>end
        
        </asp:Panel>
        </form>

</body>
</html>


and connection class:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Microsoft.Reporting.WebForms;
using System.Net;
using System.Configuration;
using System.Security.Principal;

namespace MvcMusicStore.Reports
{
    [Serializable]
    public class ReportServerConnection : IReportServerConnection2
    {
        public Uri ReportServerUrl
        {
            get
            {
                string url = ConfigurationManager.AppSettings["ReportViewerPath"]; //http://localhost/ReportServer
                if (string.IsNullOrEmpty(url))
                    throw new Exception("Missing url from the Web.config file");
                return new Uri(url);
            }
        }
        public int Timeout
        {
            // set timeout to 60 seconds
            get { return 60000; }
        }

        public IEnumerable<Cookie> Cookies
        {
            // No custom cookies
            get { return null; }
        }
        public IEnumerable<string> Headers
        {
            // No custom headers
            get { return null; }
        }

        public GEMReportServerConnection()
        {
        }


        public WindowsIdentity ImpersonationUser
        {
            get { return null; }
        }

        public ICredentials NetworkCredentials
        {
            get
            {
                // return null will force the use of impersonation, 
                // otherwise, remove the return null and 
                // implement the other app settings to specify the credential details
                // return null;                

                string userName = ConfigurationManager.AppSettings["ReportViewerUser"];
                if (string.IsNullOrEmpty(userName))
                    throw new Exception("Missing user name from Web.config file");
                string password = ConfigurationManager.AppSettings["ReportViewerPassword"];
                if (string.IsNullOrEmpty(password))
                    throw new Exception("Missing password from Web.config file");
                string domain = ConfigurationManager.AppSettings["ReportViewerDomain"];
                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;
            return false;
        }
    }
}


I''m guessing my ajax:ToolkitScriptManager works fine (is there a way to test it?). Any ideas?

解决方案

<asp:scriptmanager id="ScriptManager1" runat="server" xmlns:asp="#unknown">

EnablePartialRendering="false">
</asp:ScriptManager


>

http://social.msdn.microsoft.com/Forums/en-GB/vsreportcontrols/thread/6219309d-030d-4618-8580-4f534b7ba55d[^]


这篇关于mvc的sql reportviewer问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆