【问题标题】:How to access an object declared in Global.asax outside of the file?如何访问文件外在 Global.asax 中声明的对象?
【发布时间】:2009-03-10 19:50:54
【问题描述】:

我在 global.asax 文件中声明了一个对象,如下所示。

<object Id="WFRuntime" RunAt="Server" Class="System.Workflow.Runtime.WorkflowRuntime" Scope="application">

虽然我能够在 global.asax 文件方法中访问此对象,但我无法在 asp.net Web 应用程序的其他地方使用它。我正在使用 .net 3.5 框架。

有什么路线吗?

谢谢, 苏格拉底。

【问题讨论】:

    标签: c# asp.net .net-3.5


    【解决方案1】:

    首先,确保您的 Global.asax 文件有代码隐藏

    <%@ Application Codebehind="Global.asax.cs" Inherits="YourSite.Global" Language="C#" %>
    

    如果您没有,请创建一个 Global.asax.cs 文件。如果您有网站而不是 Web 项目,则此必须位于您的 App_Code 目录中。它必须看起来像这样:

    namespace YourSite {
        public class Global : HttpApplication {
            public System.Workflow.Runtime.WorkflowRuntime WFRuntime { get; set; }
        }
    }
    

    这应该使您网站中的所有页面都可以引用 ((Global)Context.Application).WFRuntime。

    或者,您可以将 WFRuntime 成员设为静态,然后在整个站点中使用“Global.WFRuntime”。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-08-25
      • 1970-01-01
      • 1970-01-01
      • 2016-11-27
      相关资源
      最近更新 更多