Specified cast is not valid problem...

V

VB Programmer

I am setting up forms authentication.

In my code I keep getting this error. Any ideas?

Error....


Server Error in '/LandOLots' Application.
--------------------------------------------------------------------------------

Specified cast is not valid.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: System.InvalidCastException: Specified cast is not valid.

Source Error:

Line 45: ' Fires upon attempting to authenticate the use
Line 46: If Request.IsAuthenticated Then
Line 47: Dim fiIndentity As FormsIdentity = CType(User.Identity,
FormsIdentity)
Line 48: If fiIndentity Is Nothing Then Exit Sub
Line 49: Dim fatTicket As Security.FormsAuthenticationTicket =
fiIndentity.Ticket()

Source File: c:\inetpub\wwwroot\LandOLots\Global.asax.vb Line: 47

Stack Trace:

[InvalidCastException: Specified cast is not valid.]
LandOLots.Global.Application_AuthenticateRequest(Object sender, EventArgs
e) in c:\inetpub\wwwroot\LandOLots\Global.asax.vb:47
System.Web.SyncEventExecutionStep.System.Web.HttpApplication+IExecutionStep.Execute()
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean&
completedSynchronously)
 
K

Kevin Spencer

You're trying to cast an IPrinciple object as a
System.Web.Security.FormsIdentity object. Unless IPrinciple inherits
System.Web.Security.FormsIdentity (which it doesn't), you cannot do that.

Casting can be done from like types, such as Float and Double, or from
inherited types, such as casting System.Web.Security.FormsIdentity to
System.Object, which it inherits.
--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Neither a follower nor a lender be.
 
V

VB Programmer

Thanks as usual.

I found out that the problem was I didn't have the web.config setup for
forms auth.

Kevin Spencer said:
You're trying to cast an IPrinciple object as a
System.Web.Security.FormsIdentity object. Unless IPrinciple inherits
System.Web.Security.FormsIdentity (which it doesn't), you cannot do that.

Casting can be done from like types, such as Float and Double, or from
inherited types, such as casting System.Web.Security.FormsIdentity to
System.Object, which it inherits.
--
HTH,

Kevin Spencer
Microsoft MVP
.Net Developer
Neither a follower nor a lender be.

VB Programmer said:
I am setting up forms authentication.

In my code I keep getting this error. Any ideas?

Error....


Server Error in '/LandOLots' Application.
--------------------------------------------------------------------------------

Specified cast is not valid.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: System.InvalidCastException: Specified cast is not
valid.

Source Error:

Line 45: ' Fires upon attempting to authenticate the use
Line 46: If Request.IsAuthenticated Then
Line 47: Dim fiIndentity As FormsIdentity =
CType(User.Identity, FormsIdentity)
Line 48: If fiIndentity Is Nothing Then Exit Sub
Line 49: Dim fatTicket As Security.FormsAuthenticationTicket
= fiIndentity.Ticket()

Source File: c:\inetpub\wwwroot\LandOLots\Global.asax.vb Line: 47

Stack Trace:

[InvalidCastException: Specified cast is not valid.]
LandOLots.Global.Application_AuthenticateRequest(Object sender,
EventArgs e) in c:\inetpub\wwwroot\LandOLots\Global.asax.vb:47

System.Web.SyncEventExecutionStep.System.Web.HttpApplication+IExecutionStep.Execute()
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean&
completedSynchronously)
 
G

Guest

VB Programmer said:
I am setting up forms authentication.

In my code I keep getting this error. Any ideas?

Error....


Server Error in '/LandOLots' Application.
--------------------------------------------------------------------------------

Specified cast is not valid.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: System.InvalidCastException: Specified cast is not valid.

Source Error:

Line 45: ' Fires upon attempting to authenticate the use
Line 46: If Request.IsAuthenticated Then
Line 47: Dim fiIndentity As FormsIdentity = CType(User.Identity,
FormsIdentity)
Line 48: If fiIndentity Is Nothing Then Exit Sub
Line 49: Dim fatTicket As Security.FormsAuthenticationTicket =
fiIndentity.Ticket()

Source File: c:\inetpub\wwwroot\LandOLots\Global.asax.vb Line: 47

Stack Trace:

[InvalidCastException: Specified cast is not valid.]
LandOLots.Global.Application_AuthenticateRequest(Object sender, EventArgs
e) in c:\inetpub\wwwroot\LandOLots\Global.asax.vb:47
System.Web.SyncEventExecutionStep.System.Web.HttpApplication+IExecutionStep.Execute()
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean&
completedSynchronously)
 

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

Top