之间http.context.user和和Thread.CurrentPrincipal中的差异时使用它们? [英] difference between http.context.user and thread.currentprincipal and when to use them?

查看:232
本文介绍了之间http.context.user和和Thread.CurrentPrincipal中的差异时使用它们?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚碰到下运行Visual Studio 2008中一个asp.net web应用程序出现错误类型不解决会员... customUserPrincipal的问题。跟踪各讨论组似乎有与Visual Studio的Web服务器的问题,当您分配对一个Thread.CurrentPrincipal中自定义主体。

I have just recently run into an issue running an asp.net web app under visual studio 2008. I get the error 'type is not resolved for member...customUserPrincipal'. Tracking down various discussion groups it seems that there is an issue with Visual Studio's web server when you assign a custom principal against the Thread.CurrentPrincipal.

在我的code,我现在用的...

In my code, I now use...

HttpContext.Current.User = myCustomPrincipal
//Thread.CurrentPrincipal = myCustomPrincipal

我很高兴我得到了错误的出路,但它回避了一个问题:是什么设置本金这两种方法之间的区别?。还有其他计算器<一href=\"http://stackoverflow.com/questions/1843271/whats-the-difference-between-httpcontext-current-user-and-thread-currentprincipa\">questions相关的差异,但它们不进入这两种方法的细节。

I'm glad that I got the error out of the way, but it begs the question "What is the difference between these two methods of setting a principal?". There are other stackoverflow questions related to the differences but they don't get into the details of the two approaches.

我没有找到一个诱人的职位,有以下宏伟的注释,但没有解释来支持他的说法...

I did find one tantalizing post that had the following grandiose comment but no explanation to back up his assertions...

使用HttpConext.Current.User所有
  网页(ASPX / ASMX)应用程序。

Use HttpConext.Current.User for all web (ASPX/ASMX) applications.

使用的Thread.CurrentPrincipal中所有
  其他应用程序一样的WinForms,
  控制台和窗口服务
  应用程序。

Use Thread.CurrentPrincipal for all other applications like winForms, console and windows service applications.

你们中的任何安全/ dot.net大师能提供一些线索对这个问题?

Can any of you security/dot.net gurus shed some light on this subject?

推荐答案

在一个web表单应用程序,我相信 Thread.CurrentPrincipal中将是任何人运行工作进程的主要(线程)。

Under a webforms application I believe Thread.CurrentPrincipal will be the principal for whomever is running the worker process (Thread).

HttpContext.Current.User 将是当前登录网络的用户。

HttpContext.Current.User will be the current logged in web-user.

在窗体/ WPF应用程序的情况下,这是有道理的,因为你下运行的应用程序的用户是你感兴趣的一个。

In the case of a forms/wpf app it makes sense because the user you're running the application under is the one you're interested in.

您试图伪装工作进程或用户登录?

Are you trying to masquerade the worker process or the logged in user?

这篇关于之间http.context.user和和Thread.CurrentPrincipal中的差异时使用它们?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆