共用方式為


LocalReport.AddTrustedCodeModuleInCurrentAppDomain 方法

注意:這個 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 AddTrustedCodeModuleInCurrentAppDomain ( _
    assemblyName As String _
)
[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 AddTrustedCodeModuleInCurrentAppDomain(
    string assemblyName
)
[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 AddTrustedCodeModuleInCurrentAppDomain(
    String^ assemblyName
)
[<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 AddTrustedCodeModuleInCurrentAppDomain : 
        assemblyName:string -> unit 
public function AddTrustedCodeModuleInCurrentAppDomain(
    assemblyName : String
)

參數

  • assemblyName
    類型:String
    要加入之組件的名稱。

備註

重要

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.

This method will continue to work with .NET Framework 3.5.

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

Expressions in the report will be executed in the current AppDomain with only the Execution security permission flag. By default, custom assemblies are not allowed in this mode. The AddTrustedCodeModuleInCurrentAppDomain method can be used to allow the use of custom assemblies in the current AppDomain.

The name of the assembly passed in the assemblyName parameter should match that specified in the CodeModule element of the report definition file.

範例

In this example, a custom assembly containing a simple utility function that calculates factorials is used as an expression in a report.

public class Util
{
    public static int Factorial(int n)
    {
        return ((n <= 1) ? 1 : (n * Factorial(n - 1))); 
    }
}

The following code is used to add the custom assembly to the current AppDomain.

reportViewer.LocalReport.ReportPath = "Report1.rdlc";

reportViewer.LocalReport.AddTrustedCodeModuleInCurrentAppDomain(
   "Contoso.Utilities, 
   Version=1.0.271.0, Culture=neutral,
   PublicKeyToken=89012dab8080cc90");

For more information on custom assemblies, see "Using Custom Assemblies with Reports" in the SQL Server Books Online.

請參閱

參考

LocalReport 類別

Microsoft.Reporting.WebForms 命名空間