2

WebアプリケーションでVS2010レポートビューアコントロールを使用しています。アプリケーションのセッション状態モードは、次のようにStateServerに設定されます

    <sessionState timeout="30" mode="StateServer" stateConnectionString="tcpip=127.0.0.1:42424" sqlConnectionString="data source=127.0.0.1;Trusted_Connection=yes" cookieless="false" />

reportviewerコントロールは開発マシンで正常に機能していますが、アプリケーションがサーバーにデプロイされ、reportviewerコントロールページが読み込まれると、次のエラーがスローされます。他のすべてのページは正常に機能しています。

「セッション状態をシリアル化できません。「StateServer」および「SQLServer」モードでは、ASP.NETはセッション状態オブジェクトをシリアル化します。その結果、シリアル化できないオブジェクトまたはMarshalByRefオブジェクトは許可されません。同様のシリアル化の場合も同じ制限が適用されます。 「カスタム」モードのカスタムセッション状態ストアによって実行されます。」

誰か助けてくれませんか、どんなアイデアでも大いに役立ちます。

前もって感謝します。


rptvw.ProcessingMode = ProcessingMode.Remote;
        rptvw.ServerReport.ReportServerUrl = new Uri("http://localhost:90/reportserver");
        rptvw.ServerReport.ReportPath = string.Format("/Reports/{0}", reportName);

        var param = new ReportParameter[4];

        param[0] = new ReportParameter("Parameter1", DropDownListCodes.SelectedValue));
        param[1] = new ReportParameter("Parameter2", DropDownListQuarters.SelectedValue));
        param[2] = new ReportParameter("Parameter3", DropDownListComparators.SelectedValue));
        param[3] = new ReportParameter("Parameter4", comptype);

        rptvw.ServerReport.SetParameters(param);

        rptvw.ServerReport.Refresh();
4

1 に答える 1

2

私はそれを機能させることができました。ソリューションのmsdnリンクについては、このリンクをたどりました

「IReportServerCredentials インターフェイスを実装するときは、ReportViewer コントロールがオブジェクトのインスタンスを ASP.NET セッションに格納することを知っておくことが重要です。サーバーの ASP.NET セッションが Reporting Services などのアウト プロセスで格納されている場合、クラスはストレージ用にシリアル化できるように、シリアル化可能とマークされています。」上記のリンクから取得。

App_Code\ReportServerConnection.cs に新しいファイルを作成しました

    [Serializable]
    public sealed class ReportServerConnection : IReportServerConnection2
    {
        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;
        }

        public WindowsIdentity ImpersonationUser
        {
            // Use the default Windows user.  Credentials will be
            // provided by the NetworkCredentials property.
            get { 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["ReportViewerUser"];

                if (string.IsNullOrEmpty(userName))
                    throw new InvalidOperationException("Please specify the user name in the project's Web.config file.");

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

                if (string.IsNullOrEmpty(password))
                    throw new InvalidOperationException("Please specify the password in the project's Web.config file");

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

                if (string.IsNullOrEmpty(domain))
                    throw new InvalidOperationException("Please specify the domain in the project's Web.config file");

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

        public Uri ReportServerUrl
        {
            get
            {
                string url = ConfigurationManager.AppSettings["ReportServerUrl"];

                if (string.IsNullOrEmpty(url))
                    throw new InvalidOperationException("Please specify the report server URL in the project's 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; }
        }
    }

Report.aspx.cs ページ

    protected void Page_Init(object sender, EventArgs e)
    {
        rptvw.ServerReport.ReportServerCredentials = new ReportServerConnection();
    }

メイン投稿のコードでこの行を変更しました rptvw.ServerReport.ReportServerUrl = rsc.ReportServerUrl;

そして Web.config で

<appSettings>
<add key="ReportViewerServerConnection" value=" App_Code.ReportServerConnection, App_Code"/>
<add key="ReportViewerUser" value="username"/>
<!-- Used as the user name by the ReportServerConnection class. -->
<add key="ReportViewerPassword" value="password"/>
<!-- Used as the password by the ReportServerConnection class. -->
<add key="ReportViewerDomain" value="domainname"/>
<!-- Used as the domain by the ReportServerConnection class. -->
<add key="ReportServerUrl" value="http://localhost:90/reportserver"/>
<!-- Used as the report server URL by the ReportServerConnection class. -->
于 2012-10-08T09:13:50.310 に答える