共用方式為


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 _
)
[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
)

參數

  • reportEvidence
    類型:Evidence
    Evidence 物件,包含報表的安全性資訊。

備註

重要

This method is deprecated for .NET Framework 4 because the code access security (CAS) feature it relies on is deprecated in .NET Framework 4.Instead, the ReportViewer control always executes in the sandboxed application domain.You should use AddFullTrustModuleInSandboxAppDomain and SetBasePermissionsForSandboxAppDomain.If you want to continue to use this method with .NET Framework 4, you must use the <NetFx40_LegacySecurityPolicy> configuration element in the Web.config file of your ASP.NET application.Otherwise, this method will throw an InvalidOperationException.

For more information, see 程式碼存取安全性原則相容性和移轉.

Expressions in the report will be run in the current AppDomain with only the Execution security permission flag. By default, custom assemblies are not allowed in this mode. In .NET Framework 3.5, this is the default mode and is the mode to use for trusted reports. See the table below for the default application domain modes in different .NET Framework versions.

.NET Framework Version

LegacySecurityPolicy Enabled?

Default Application Domain

Useable Application Domain Modes

4

No (Default)

Sandboxed

Sandboxed

4

Yes

Current

Sandboxed and current

3.5

N/A

Current

Sandboxed and current

This mode may also be used to run untrusted reports that do use trusted processing extensions.

To allow trusted processing extensions, the application must call AddTrustedCodeModuleInCurrentAppDomain.

範例

In this example, a custom assembly containing a simple utility function that reads some data from a text file is used as an expression in a report.

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;
    }
}

The following code is used to allow the report with the custom assembly to execute in the current 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 命名空間