I am Using Method UserPrincipal.Current.ToString()
in Domain to Get Current Logged in Domain User with Valid Domain. but when i am Displaying it in a string its giv
I have seen this exception when running under IIS 7 on Windows 7.
System.Security.Principal.WindowsIdentity.GetCurrent().Name returns "IIS APPPOOL\ASP.NET v4.0".
This is not a real user account, which partly explains what is happening, though IMHO UserPrincipal.Current
should handle this situation more gracefully.
I think it's a bug and have created a bug on Connect:
http://connect.microsoft.com/VisualStudio/feedback/details/748790/userprincipal-current-throws-invalidcastexception
As a workaround, use System.Security.Principal.WindowsIdentity.GetCurrent()
to get the identity of an IIS AppPool.