ASP.net 网络服务
我正在使用一个 Web 服务,它在登录时设置 Thread.CurrentPrincipal 对象,不久之后,当同一 Web 服务的另一个 Webmethod 访问 Thread.CurrentPrincipal 时,它的不同/重置
有人可以告诉我这是否是预期的,或者可以从不同的 Webmethod 调用同一客户端可以访问同一 Thread.CurrentPrincipal 对象
谢谢
I am using a web service which sets the Thread.CurrentPrincipal object while logging in and soon later when another webmethod of the same web service accesses Thread.CurrentPrincipal, its different/resets
Can someone tell me if this is expected or can different webmethod calls from the same client can access the same Thread.CurrentPrincipal object
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
![扫码二维码加入Web技术交流群](/public/img/jiaqun_03.jpg)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
一旦停止使用线程,它就会返回到线程池中。
下一次调用将从线程池中获取一个线程,但您无法控制获取哪个线程。
您需要在每个请求中发送有关哪个用户正在拨打电话的信息。
As soon as you stop using a thread it goes back into the thread pool.
The next call will take a thread from the thread pool, but you have no control which one you get.
You need to send information about which user is making the call, with each request.
这是预料之中的,每个新的网络请求实际上都是新的线程。每个 Web 请求都会重置 CurrentThread、CurrentCulture 等内容。
您想要做的是身份验证会话。有很多可能的解决方案。但为了提出建议,我必须指定您使用的技术。
例如,ASP.NET ASMX 服务可以使用表单身份验证。他们还了解 ASP.NET 会话。
使用 WCF,您可以启用 ASP.NET 支持,因此您将拥有与 ASP.NET ASMX 服务相同的内容。但您也可以利用 Windows Communication Foundation 身份验证服务。
无论如何需要您提供更多信息。
This is expected, every new web request is actually new thread. And every web request reset stuff like CurrentThread, CurrentCulture and so on.
What are you trying to do is authentication session. There are many possible solutions. But to suggest something I have to specify technology you use.
For example, ASP.NET ASMX Services can use Forms Authentication. Also they are aware about ASP.NET Session.
With WCF, you can enable ASP.NET support, so you will have same stuff like for ASP.NET ASMX Services. But you also can leverage on Windows Communication Foundation Authentication Service.
Anyways need more info from you.
如果您对网站使用内置的 ASP .NET 身份验证,然后仅从网页调用 Web 服务,则可以通过修饰在 Web 服务的方法中启用会话变量和用户上下文信息。像这样:
如果这不能解决您的问题,请告诉我们您使用 Thread.CurrentPrincipal 对象做什么(您从 Thread.CurrentPrincipal 对象中提取什么)。也许还有另一种解决方案。
If you are using the built-in ASP .NET authentication for your website and then just calling the web service from a web page, you may be able to enable session variables and user context information in the methods of the web service with a decoration. Like this:
If that doesn't solve your problem, tell us what are you using the Thread.CurrentPrincipal object for (what you are pulling out of the Thread.CurrentPrincipal object). Perhaps there is another solution.