IIdentity casting problem

C

Craig Buchanan

I have an object, named SiteIdentity, that implements IIdentity. I have
added additional properties to this class, Email for instance. I am using
forms authentication.

In the code behind class for a webform, I try to cast from the HttpContext
identity object to my SiteIdentity object, but I get an error that reads
"Specified cast not valid". Here's the code:

If context.User.Identity.IsAuthenticated Then
Response.Write( Ctype( context.User.Identity,
MySite.Framework.Security.SiteIdentity).Email )
...

What am I missing?

Thanks,

Craig Buchanan
 
T

Teemu Keiski

Hi,

have you assigned your custom principal/identity object to the
HttpContext.User on every request?

--
Teemu Keiski
MCP, Microsoft MVP (ASP.NET), AspInsiders member
ASP.NET Forum Moderator, AspAlliance Columnist

I have an object, named SiteIdentity, that implements IIdentity. I have
added additional properties to this class, Email for instance. I am using
forms authentication.

In the code behind class for a webform, I try to cast from the HttpContext
identity object to my SiteIdentity object, but I get an error that reads
"Specified cast not valid". Here's the code:

If context.User.Identity.IsAuthenticated Then
Response.Write( Ctype( context.User.Identity,
MySite.Framework.Security.SiteIdentity).Email )
...

What am I missing?

Thanks,

Craig Buchanan
 
B

bruce barker

the error means that context.User.Identity is not a
MySite.Framework.Security.SiteIdentity. where is your code that sets
SiteIdenity to one of your objects.

-- bruce (sqlwork.com)
 
C

Craig Buchanan

Teemu-

Does it need to be on *every* request? How about just on the
Global_AcquireRequestState method the of the global.asax?

Thanks,

Craig
 
C

Craig Buchanan

bruce-

looks like i'm only doing this on an actual database authentication. i'm
not doing anything if it is a stored asp.net auth. cookie.

where should i be setting the siteidentity in this case?

craig
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top