Live Code runs in IIS and ASP.NET Web Server but not IIS Express
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.MyP开发者_如何学JAVArincipal.
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?
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.
精彩评论