实时代码在 IIS 和 ASP.NET Web Server 中运行,但不在 IIS Express 中运行

发布于 2024-11-02 20:16:18 字数 719 浏览 4 评论 0原文

最近安装了 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 技术交流群。

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

发布评论

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

评论(1

落叶缤纷 2024-11-09 20:16:18

我认为你想要 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.

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