2011-04-21 96 views
1

最近安装IIS Express时,我希望它能让我的生活更轻松,但我几乎马上就遇到了问题。实时代码在IIS和ASP.NET Web服务器上运行,但不是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服务器下运行的代码(卡西尼)一切都很好,我可以看到,是Thread.CurrentPrincipal中类型MyCustomAuthentication的.Principal.MyPrincipal。

在IIS Express下运行此相同的行会引发InvalidCastException并检查类型,我发现它现在是System.Security.Principal.GenericPrincipal,因为没有其他更改会造成混淆。

我可以确认MyCustomAuthentication.Principal.MyPrincipal实现IPrincipal并记住这是实时代码,它目前正在部署和运行。

任何人都可以对这里发生的事情有所了解吗?

+0

你有没有解决这个问题?我有同样的问题 – LenPopLilly 2012-04-15 08:31:04

+0

@LillyPop:恐怕我从来没有解决这个问题 - 我想我最终使用了全面的IIS,而且它运行良好(一年前,现在我已经从这项工作中移出)。 – DilbertDave 2012-04-17 12:23:37

回答

0

我想你想要HttpContext.Current.User代替。当前用户的身份与当前线程的身份不同。

+0

谢谢斯科特 - 当我回去工作时(长周末),我会放弃这一点。我很困惑,为什么这是在生产环境中工作,而不是在IIS Express下工作。 – DilbertDave 2011-04-22 08:11:47

+0

我已经更新了代码,并且问题依然存在 - HttpContext.Current.User作为System.Security.Principal.GenericPrincipal出现,我得到一个InvalidCastException。 – DilbertDave 2011-04-26 08:05:13