Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
BOOK: ASP.NET Website Programming Problem-Design-Solution
This is the forum to discuss the Wrox book ASP.NET Website Programming: Problem - Design - Solution, Visual Basic .NET Edition by Marco Bellinaso, Kevin Hoffman; ISBN: 9780764543869
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: ASP.NET Website Programming Problem-Design-Solution section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old October 9th, 2003, 06:47 AM
Registered User
 
Join Date: Sep 2003
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Specified cast is not valid

The MyAccount.aspx page is throwing the error 'Specified cast is not valid' for the line:

Dim currentUser As New AccBusiness.User( _
                      CType(Context.User, SitePrincipal))

Any thoughts on why this might be?
Id really appreaciate any help on this one, thanks.

  #2 (permalink)  
Old October 20th, 2003, 10:29 AM
Registered User
 
Join Date: Jul 2003
Location: , , .
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I had the same problem. It worked when I first started using the site.

I fixed it by adding the MyAccount.aspx and MyAccount.aspx.vb from the original download into the project overwriting the existing files. Re-booted my computer and re-built the solution. Works fine now.

  #3 (permalink)  
Old October 20th, 2003, 10:44 AM
Registered User
 
Join Date: Jul 2003
Location: , , .
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Scratch that! Problem started again.

  #4 (permalink)  
Old October 20th, 2003, 09:57 PM
Registered User
 
Join Date: Oct 2003
Location: , , .
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I'm getting the same error when I try to cast the context.user.identity object to a SiteIdentity object in the siteheader.ascx user control. The line that causes the issue is

Dim id As SiteIdentity = CType(Context.User.Identity(), SiteIdentity)

Below is the stack trace. If anyone knows how to resolve this a solution would be greatly appreciated. In the mean time I'll keep banging my head on the keyboard.

[InvalidCastException: Specified cast is not valid.]
   home.Opydcom.Web.Controls.User.SiteHeader.Page_Loa d(Object sender, EventArgs e) in C:\Inetpub\web\opyd\wwwroot2\html\home\Controls\Us er\SiteHeader.ascx.vb:57
   System.Web.UI.Control.OnLoad(EventArgs e) +67
   System.Web.UI.Control.LoadRecursive() +35
   System.Web.UI.Control.LoadRecursive() +98
   System.Web.UI.Control.LoadRecursive() +98
   System.Web.UI.Page.ProcessRequestMain() +725



  #5 (permalink)  
Old October 21st, 2003, 02:17 PM
Registered User
 
Join Date: Aug 2003
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Check out this thread, I'm sure that is what is happening to you.

I've email wrox and the authors to try and fix this error. They either don't know how to fix this or just don't care.

http://p2p.wrox.com/topic.asp?TOPIC_ID=1361

  #6 (permalink)  
Old October 21st, 2003, 05:37 PM
Registered User
 
Join Date: Oct 2003
Location: , , .
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I tried the fix with the initialize sub and althought my code did seem to be altered changing back to the orignial code did not correct the invalid cast error.


  #7 (permalink)  
Old October 21st, 2003, 08:12 PM
Registered User
 
Join Date: Oct 2003
Location: , , .
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I have found a work around to the problem I was having. I have posted an updated page_load sub below. Changes from the original are in BOLD. Note that I have added a couple of trace.write statements for debug purposes to check the object type of my Context.user object. The two trace.write lines can be omitted with no ill effects.


 Private Sub Page_Load(ByVal sender As Object, _
          ByVal e As EventArgs) Handles MyBase.Load

            Greeting.Text = "Welcome, "
           Dim id As SiteIdentity
            If Context.User.Identity.IsAuthenticated Then

                Trace.Write("is SitePrincipal:" & (TypeOf context.User Is SitePrincipal).ToString)
                Trace.Write("User is Authenticated: " & Context.User.Identity.IsAuthenticated.ToString)


               If Not (TypeOf context.User Is SitePrincipal) Then
                    id = New SiteIdentity(Context.User.Identity.Name)
                End If

                Greeting.Text = Greeting.Text & "<b>" & id.name & "</b>"
                UserLink.Text = "My Account"
                UserLink.NavigateUrl = _
                "/home/WebModules/Accounts/MyAccount.aspx"
                SignOut.Visible = True

            Else

                Greeting.Text = Greeting.Text & "Guest User."
                UserLink.Text = "Click to Login"
                UserLink.NavigateUrl = "/home/WebModules/Accounts/Login.aspx"
                SignOut.Visible = False

            End If

        End Sub

  #8 (permalink)  
Old October 28th, 2003, 08:44 PM
Registered User
 
Join Date: Oct 2003
Location: Pittsburgh, PA, USA.
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

You need to make your pages inherit the general page class. Make sure your MyAccount.apsx.vb code page has:
Code:
    Public Class MyAccount
        Inherits Wrox.ThePhile.Web.PhilePage
  #9 (permalink)  
Old November 6th, 2003, 07:08 PM
Registered User
 
Join Date: Nov 2003
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

The code was regenerated when any control is added/removed on the ASPX to:

    Private Sub InitializeComponent()
    End Sub
    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

THEREFORE, the PhilePage.PhilePage_Load was not run. We should just changed them back like:
    Private Sub InitializeComponent()
      AddHandler Me.Load, AddressOf Page_Load
    End Sub
   Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)

I DON'T known if we can disable this code regeneration option!
  #10 (permalink)  
Old November 1st, 2004, 05:09 PM
Authorized User
 
Join Date: Nov 2003
Location: , , .
Posts: 37
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to seanmayhew
Default

I find I only get this error if I log out of my current principal and try to visit the account page without being logged in you know by just going to the page directly. Its as if the page needs a "You need to be logged in to view the "My Account" page.



Similar Threads
Thread Thread Starter Forum Replies Last Post
Specified cast is not valid. ayem Visual Studio 2008 1 September 8th, 2008 09:15 PM
Specified cast is not valid surajb Crystal Reports 0 January 12th, 2007 02:03 PM
Specified cast is not valid. abstar BOOK: ASP.NET Website Programming Problem-Design-Solution 2 March 31st, 2005 03:00 PM
"Specified cast is not valid" help BaBaBooey ASP.NET 1.0 and 1.1 Basics 2 November 23rd, 2004 12:12 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.