2

我正在使用的Web應用程序VS2010報表查看器控件的應用SessionState的模式設置爲StateServer如下的ReportViewer - 「無法序列化會話狀態‘的StateServer’和‘SQLSERVER’模式

<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(); 
+1

我認爲你錯過了'初始目錄='在此連接字符串,或您嘗試添加到會話列表,不能序列化,如Dictionary <> – Aristos

+0

感謝您的回覆。上面的標記不是連接字符串,它是一個sessionState標記。只是爲了讓您知道,我沒有在該頁面的會話中存儲任何內容。只需使用reportviewer控件加載.rdlc報告。 – Savvy

+0

正如@Aristos所說,您應該檢查ReportViewer頁面上的會話內容。據我所知,房車在會話 – jbl

回答

1

我設法得到它的工作。 我跟着這個鏈接,我的解決方案msdn link

「在實現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(); 
    } 

改變了這一行代碼的M ain post 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. --> 

相關問題