实时代码在 IIS 和 ASP.NET Web Server 中运行,但不在 IIS Express 中运行
最近安装了 IIS Express,我希望它能让我的生活更轻松,但我几乎立刻就遇到了问题。
考虑以下代表一些实时代码的内容:
Public Shared Function GetServiceId() As String
Dim principal As MyCustomAuthentication.Principal.MyPrincipal
principal = CType(Thread.CurrentPrincipal, MyCustomAuthentication.Principal.MyPrincipal)
.
.
.
.
End Function
在 ASP.NET Web 服务器 (Cassini) 下运行代码一切正常,我可以看到 Thread.CurrentPrincipal 的类型为 MyCustomAuthentication.Principal.MyPrincipal。
在 IIS Express 下运行同一行会抛出 InvalidCastException 并检查我发现它现在是 System.Security.Principal.GenericPrincipal 的类型,这很令人困惑,因为其他任何内容都没有改变。
我可以确认 MyCustomAuthentication.Principal.MyPrincipal 实现了 IPrincipal 并记住这是实时代码,它当前已部署并正在运行。
谁能解释一下这里发生的事情吗?
Having recently installed IIS Express I was hoping that it was going to make life easier for me, but I've run into a problem almost straight away.
Consider the following which is representative of some live code:
Public Shared Function GetServiceId() As String
Dim principal As MyCustomAuthentication.Principal.MyPrincipal
principal = CType(Thread.CurrentPrincipal, MyCustomAuthentication.Principal.MyPrincipal)
.
.
.
.
End Function
Running the code under the ASP.NET Web Server (Cassini) everything is fine and I can see that Thread.CurrentPrincipal is of type MyCustomAuthentication.Principal.MyPrincipal.
Running under IIS Express this same line throws an InvalidCastException and checking the type I find it is now of System.Security.Principal.GenericPrincipal which is confusing as nothing else has changed.
I can confirm that MyCustomAuthentication.Principal.MyPrincipal implements IPrincipal and remember this is Live code, it is currently deployed and working.
Can anyone shed any light on what is going on here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为你想要 HttpContext.Current.User 。当前用户的身份与当前线程的身份不同。
I think you want HttpContext.Current.User instead. The identity of the current User isn't the same as the identity of the current thread.