IHttpModule Init 未触发

发布于 2024-09-06 22:00:58 字数 1667 浏览 10 评论 0原文

我遇到了 contextInfo 问题

[WebMethod]
[SoapHeader("UserInfo", Direction = SoapHeaderDirection.In)]
public void TestContext()
        {
            var user = ContextInfo.Current.User.LoginName;
        }

UserInfo _userInfo;
        [System.Xml.Serialization.SoapElement(IsNullable = true)]
        public UserInfo UserInfo
        {
            get { return _userInfo; }
            set { _userInfo = value; }
        }

当我在本地运行我的 asmx 时一切正常,它进入

public void Init(HttpApplication httpApp).

但是当我在服务中运行我的 webservice 时却没有,并且我收到错误,

ContextInfo.Current.User.LoginName;

因为 Current 为空。

我通过远程调试器检查这一点。

我有 Windows Server 2008,并且我在像我的服务器一样的域中。

public class AuthenticateRequestHttpModule : IHttpModule
    {

        private HttpApplication mHttpApp;

        public void Init(HttpApplication httpApp)
        {
            this.mHttpApp = httpApp;

            mHttpApp.AuthenticateRequest += new EventHandler(OnAuthentication);
        }
...
}

ContextInfo:

public class ContextInfo
{

    public static void Create(User user)
    {
        HttpContext.Current.Items.Add(ITEM_KEY, new ContextInfo(user));
    }

          public static ContextInfo Current
    {
        get
        {
            return HttpContext.Current.Items[ITEM_KEY] as ContextInfo;
        }
    }


         private ContextInfo(User user)
    {

        _user = user;
    }

    public User User
    {
        get { return _user; }
    }


    User _user;
    private const string ITEM_KEY = "ContextInfo";
}

有什么想法吗?

I have got problem with contextInfo

[WebMethod]
[SoapHeader("UserInfo", Direction = SoapHeaderDirection.In)]
public void TestContext()
        {
            var user = ContextInfo.Current.User.LoginName;
        }

UserInfo _userInfo;
        [System.Xml.Serialization.SoapElement(IsNullable = true)]
        public UserInfo UserInfo
        {
            get { return _userInfo; }
            set { _userInfo = value; }
        }

When I run my asmx at local everything goes fine, it enter to

public void Init(HttpApplication httpApp).

But when I run my webservice at service it doesn't and I get error at

ContextInfo.Current.User.LoginName;

because Current is null.

I check this by remote debugger.

I have Windows Server 2008 and I am in domain like my server.

public class AuthenticateRequestHttpModule : IHttpModule
    {

        private HttpApplication mHttpApp;

        public void Init(HttpApplication httpApp)
        {
            this.mHttpApp = httpApp;

            mHttpApp.AuthenticateRequest += new EventHandler(OnAuthentication);
        }
...
}

ContextInfo:

public class ContextInfo
{

    public static void Create(User user)
    {
        HttpContext.Current.Items.Add(ITEM_KEY, new ContextInfo(user));
    }

          public static ContextInfo Current
    {
        get
        {
            return HttpContext.Current.Items[ITEM_KEY] as ContextInfo;
        }
    }


         private ContextInfo(User user)
    {

        _user = user;
    }

    public User User
    {
        get { return _user; }
    }


    User _user;
    private const string ITEM_KEY = "ContextInfo";
}

Any ideas ?

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

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

发布评论

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

评论(1

我不会写诗 2024-09-13 22:00:58

应用程序池出现问题。

there was a problem with application pool.

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