Re: ADFS System.Web.Security.SingleSignOn.SingleSignOnIdentity



It doesn't look like ADFS is running on the machine you are working with.
The ADFS HTTP Module runs and once the user logs in, it will generate that
SingleSignOnIdentity class and stick it in Context.User.Identity. According
to your stack trace, it is currently a GenericIdentity instead.

I have no idea why that cast expression doesn't work. That's pretty weird.

If you are trying to build a claims aware app on a development machine that
isn't actually running the ADFS web agent, you will need to resort to
trickery to get an instance of the SingleSignOnIdentity class. You could
use a mock objects framework to have it build one for you or do some hacking
to use reflection to generate one. You would also wrap the whole
SingleSignOnIdentity in an interface and create a provider model that
generates a stub implemenation at runtime for testing. If I was going to do
this a lot or needed a way to create a bunch of unit tests, I'd probably do
one of those things.

Joe K.

--
Joe Kaplan-MS MVP Directory Services Programming
Co-author of "The .NET Developer's Guide to Directory Services Programming"
http://www.directoryprogramming.net
--
"Todd Fleenor" <ToddFleenor@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:CB66B70E-5122-4D56-A540-9E6F1FA66401@xxxxxxxxxxxxxxxx
In the three code examples I have found thus far for programming claims
aware
applications with ADFS, the SingleSignOnIdentity class from the
System.Web.Security.SingleSignOn namespace appears to be "castable" in an
ASP.NET 2.0 C# application as follows:

SingleSignOnIdentity id = (SingleSignOnIdentity)User.Identity;

However, in my setup, it does not appear to be allowed by Visual Studio
2005.

If I use the alternate form (the keyword "as"), the complier goes right by
with no errors:

SingleSignOnIdentity ssoID = User.Identity as SingleSignOnIdentity;

However, ssoID is set to null.

I am looking for hints or suggestions on correcting my C# syntax or VS
setup
to get past the error. Thanks

More information:
System.InvalidCastException was unhandled by user code
Message="Unable to cast object of type
'System.Security.Principal.GenericIdentity' to type
'System.Web.Security.SingleSignOn.SingleSignOnIdentity'."
Source="App_Web_osg74sak"
StackTrace:
at _Default.showVarsButton_Click(Object sender, EventArgs e) in
c:\Inetpub\wwwroot\Default.aspx.cs:line 27
at System.Web.UI.WebControls.Button.OnClick(EventArgs e)
at System.Web.UI.WebControls.Button.RaisePostBackEvent(String
eventArgument)
at
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String
eventArgument)
at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler
sourceControl, String eventArgument)
at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection
postData)
at System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)


.