共用方式為


LocalReport.ExecuteReportInCurrentAppDomain 方法

注意:此 API 已經過時。

造成在目前 AppDomain 中執行報表的處理延伸模組和運算式。

命名空間:  Microsoft.Reporting.WebForms
組件:  Microsoft.ReportViewer.WebForms (在 Microsoft.ReportViewer.WebForms.dll 中)

語法

'宣告
<ObsoleteAttribute("This method requires Code Access Security policy, which is deprecated.  For more information please go to https://go.microsoft.com/fwlink/?LinkId=160787.")> _
Public Sub ExecuteReportInCurrentAppDomain ( _
    reportEvidence As Evidence _
)
'用途
Dim instance As LocalReport
Dim reportEvidence As Evidence

instance.ExecuteReportInCurrentAppDomain(reportEvidence)
[ObsoleteAttribute("This method requires Code Access Security policy, which is deprecated.  For more information please go to https://go.microsoft.com/fwlink/?LinkId=160787.")]
public void ExecuteReportInCurrentAppDomain(
    Evidence reportEvidence
)
[ObsoleteAttribute(L"This method requires Code Access Security policy, which is deprecated.  For more information please go to https://go.microsoft.com/fwlink/?LinkId=160787.")]
public:
void ExecuteReportInCurrentAppDomain(
    Evidence^ reportEvidence
)
[<ObsoleteAttribute("This method requires Code Access Security policy, which is deprecated.  For more information please go to https://go.microsoft.com/fwlink/?LinkId=160787.")>]
member ExecuteReportInCurrentAppDomain : 
        reportEvidence:Evidence -> unit 
public function ExecuteReportInCurrentAppDomain(
    reportEvidence : Evidence
)

參數

備註

重要事項重要事項

由於這個方法依賴的程式碼存取安全性 (CAS) 功能在 .NET Framework 4 中已被取代,所以這個方法在 .NET Framework 4 中已被取代。相反地,ReportViewer 控制項永遠是在沙箱應用程式定義域中執行。您應該使用 AddFullTrustModuleInSandboxAppDomainSetBasePermissionsForSandboxAppDomain。如果您想要繼續使用這個方法搭配 .NET Framework 4.0,必須在 ASP.NET 應用程式的 Web.config 檔案中使用 <NetFx40_LegacySecurityPolicy> 組態項目。否則這個方法會擲回 InvalidOperationException

如需詳細資訊,請參閱Code Access Security Policy Compatibility and Migration

報表中的運算式將會在只有執行安全性權限旗標的目前 AppDomain 中執行。依預設,自訂組件不能執行這個模式。在 .NET Framework 3.5 中,這是預設模式,也是用於信任之報表的模式。如需不同 .NET Framework 版本中的預設應用程式定義域模式,請參閱下表。

.NET Framework 版本

啟用 LegacySecurityPolicy?

預設應用程式定義域

可使用的應用程式定義域模式

4

否 (預設值)

沙箱

沙箱

4

目前

沙箱和目前

3.5

N/A

目前

沙箱和目前

此模式也可用來執行未受信任的報表 (該報表會使用受信任的處理延伸模組)。

若要接受信任的處理延伸模組,應用程式必須呼叫 AddTrustedCodeModuleInCurrentAppDomain

範例

在這個範例中,包含會從文字檔中讀取某些資料之簡單公用程式函式的自訂組件,會用來做為報表中的運算式。

using System.IO;
using System.Reflection;

public class Util
{
    public static string GetData()
    {
        StreamReader sr = new StreamReader("data.txt");
        string data = sr.ReadToEnd();
        sr.Close();
        return data;
    }
}

下列程式碼是用來允許具有自訂組件的報表在目前的 AppDomain 中執行。

reportViewer.LocalReport.ReportPath = "Report1.rdlc";
reportViewer.LocalReport.ExecuteReportInCurrentAppDomain(
      Assembly.GetExecutingAssembly().Evidence);
reportViewer.LocalReport.AddTrustedCodeModuleInCurrentAppDomain("Contoso.Utilities, 
      Version=1.0.271.0, Culture=neutral, PublicKeyToken=89012dab8080cc90");

請參閱

參考

LocalReport 類別

Microsoft.Reporting.WebForms 命名空間