forms identity problem

  • Thread starter Thread starter Darin Shaw
  • Start date Start date
D

Darin Shaw

I'm receiving a "specified cast is invalid" with the following code, though
I've used the exact same code in other applications with success. Can anyone
tell me what I'm missing or if there are other factors to be considered
here?
Thanks in advance.

========
Private Sub Page_Load(ByVal sender as System.Object, ByVal e as
System.EventArgs) Handles MyBase.Load

Dim objFormsID as FormsIdentity
objFormsID = User.Identity <=== specified cast
invalid
....
End Sub
========
 
Darin Shaw said:
I'm receiving a "specified cast is invalid" with the following code, though
I've used the exact same code in other applications with success. Can anyone
tell me what I'm missing or if there are other factors to be considered
here?
Thanks in advance.

========
Private Sub Page_Load(ByVal sender as System.Object, ByVal e as
System.EventArgs) Handles MyBase.Load

Dim objFormsID as FormsIdentity
objFormsID = User.Identity <=== specified cast
invalid

So, I guess User.Identity is not a FormsIdentity.
 
As that reply was quite unhelpful, perhaps I have not been clear enough.
I'm curious as to why this code is used successfully in text books and has
worked in other web applications of mine, but does not work in this one. Can
anyone offer any insight as to what criteria must be met for this cast to be
made, or why this would incur the stated runtime error in one case but not
another?
Thanks in advance.
 
Because in your instance, User.Identity does not reference a FormsIdentity,
but rather some other type of object. I recommend you use the debugger to
find out what kind of object it is. If you'd rather not, try
Response.Write(User.Identity.GetType().FullName), and put a REM in front of
the line which fails.

If this question is still not helpful, perhaps you could tell us what part
of it you don't understand.

--
John

Darin Shaw said:
As that reply was quite unhelpful, perhaps I have not been clear enough.
I'm curious as to why this code is used successfully in text books and has
worked in other web applications of mine, but does not work in this one. Can
anyone offer any insight as to what criteria must be met for this cast to be
made, or why this would incur the stated runtime error in one case but not
another?
Thanks in advance.
 
I know what type it is. It's an IIdentity.
My question was, and is, why it is able to cast an IIdentity to the
FormsIdentity variable in some cases, but not others.

John Saunders said:
Because in your instance, User.Identity does not reference a FormsIdentity,
but rather some other type of object. I recommend you use the debugger to
find out what kind of object it is. If you'd rather not, try
Response.Write(User.Identity.GetType().FullName), and put a REM in front of
the line which fails.

If this question is still not helpful, perhaps you could tell us what part
of it you don't understand.

--
John

Darin Shaw said:
As that reply was quite unhelpful, perhaps I have not been clear enough.
I'm curious as to why this code is used successfully in text books and has
worked in other web applications of mine, but does not work in this one. Can
anyone offer any insight as to what criteria must be met for this cast
to
 
Darin Shaw said:
I know what type it is. It's an IIdentity.
My question was, and is, why it is able to cast an IIdentity to the
FormsIdentity variable in some cases, but not others.

No, you don't know.

IIdentity is an interface. Many different classes implement IIdentity.
FormsIdentity is only one of them. GenericIdentity and WindowsIdentity are
others. Neither of the latter two are the same as FormsIdentity, so neither
can be cast to FormsIdentity.

For some reason, you're getting a different type of authentication than you
had intended. You need to follow my suggestion and either look at
User.Identity in the debugger, or write it out with Response.Write.
 
Back
Top