最早访问 .net 生命周期

发布于 2024-07-12 08:20:00 字数 775 浏览 6 评论 0原文

查看 .net 上的 IIS7 应用程序生命周期后:

http://msdn.microsoft .com/en-us/library/ms178473.aspx

为了获得最大性能,我想找到一种方法,在创建 HttpContext 对象后但在 HttpApplication 之前启动我的代码。 (在加载 HttpApplication 类之后但在使用 HTTP 模块的构造函数触发任何事件之前运行代码很容易,如下所示:

    public class AuthModule : IHttpModule 
    {     
        public AuthModule()
        {
            HttpContext.Current.Response.Write("hello world");
            HttpContext.Current.Response.End();
        }

        #region IHttpModule Members

        public void Dispose()
        {  }

        public void Init(HttpApplication context)
        {   }

        #endregion
    }

我知道我无法访问 User 对象,但我不会需要它。

After looking at the .net on IIS7 application lifecycle:

http://msdn.microsoft.com/en-us/library/ms178473.aspx

For maximum performance, I want to find a way to get my code started as soon as the HttpContext object is created but before HttpApplication is. (it's easy to run code after the HttpApplication class is loaded but before any of it's event are triggered by using the contructor of an HTTP Module like this:

    public class AuthModule : IHttpModule 
    {     
        public AuthModule()
        {
            HttpContext.Current.Response.Write("hello world");
            HttpContext.Current.Response.End();
        }

        #region IHttpModule Members

        public void Dispose()
        {  }

        public void Init(HttpApplication context)
        {   }

        #endregion
    }

I know that i won't get access to the User object, but i won't need it.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

冰葑 2024-07-19 08:20:00

您永远无法确定您的代码在创建 HttpApplication 实例之前启动,因为这些实例可能会被重用。

此外,在此阶段运行代码超出了管道的范围。 它应该让你问自己这是否真的是明智之举。

这与性能有何关系? 您真的认为创建 HttpApplication 实例的时间会记录在您的性能中吗?

退一步重新考虑。

You cannot ever be sure your code starts before the HttpApplication instance is created, since these instances may be reused.

Also, running code at this stage is beyond the scope of the pipeline. It should make you ask yourself whether it's really a sensible thing to do.

And what's this about performance? You really think the time to create an instance of HttpApplication is going to register in your performance?

Take a step back and reconsider.

浅黛梨妆こ 2024-07-19 08:20:00

请查看 MSDN 上的生命周期事件。 如果您想要早于正常页面事件的事件,您可以考虑使用这些事件之一。

Look at the life-cycle events on MSDN. You can consider using one of those events if you want something earlier than the normal page events.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文