Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| FAQ | Members List | Calendar | 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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old December 7th, 2004, 06:50 AM
Registered User
 
Join Date: Dec 2004
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Invalid cast in MyAccount.aspx

Hi,

I am having problems running the MyAccount.aspx page. I get an error saying "Specified cast is not valid." for this code:

                Wrox.WebModules.Accounts.Business.User currentUser =
                        new Wrox.WebModules.Accounts.Business.User( (Wrox.WebModules.Accounts.Business.PhilePrincipal) Context.User );

Any ideas ? I am running .NET 1.1

Carin

  #2 (permalink)  
Old December 7th, 2004, 03:35 PM
Registered User
 
Join Date: Dec 2004
Location: , , USA.
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hello,

I am developing a site using the book as a guideline and I ran into this as well. The problem (for me at least) is that the Page_Load event runs for the inherited class before it runs for the base site page class...so the Context.User has not been populated with a SitePrincipal before the page attempts to cast it as such.

When I read the chapter on the PhilePage sitewide page class, I did not understand how registering for the Page_Load (in the PhilePage OnInit method) event would guarantee that the base PhilePage_Load would be called first. From my understanding of .NET events, the order in which delegates are called is not specified. So even though the base PhilePage_Load delegate is registered first, it does not necessarily get called first. When I run in the debugger, the Page_Load for the Page is executed before the base PhilePage_Load.

I solved the problem by placing the code from the PhilePage_Load into an override of the PhilePage OnLoad method. I placed the code before a call to the base.OnLoad method to ensure it would execute first.

I do not understand how the code could work as written so I hope someone comments on what guarantees the order of execution of the Page_Load event handlers.

dg
  #3 (permalink)  
Old December 10th, 2004, 05:28 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: Atlanta, Georgia, USA.
Posts: 917
Thanks: 0
Thanked 0 Times in 0 Posts
Default

This has been addressed a lot of times here. Changing the order of 2 lines of code in the auto-generated code is all you need to do.
http://p2p.wrox.com/archive/aspdotne.../2002-06/5.asp
  #4 (permalink)  
Old December 15th, 2004, 11:47 AM
Registered User
 
Join Date: Dec 2004
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I am also getting a similar 'Invalid Cast' message on quite a few of my forms. I have checked that the page load and initialise is in the correct order and I have double checked the article related to this issue that Englere mentioned.
The code in http://p2p.wrox.com/archive/aspdotne.../2002-06/5.asp is for C# and I am using VB.NET, but changed the order of the initialize and myBase.load code anyway. Checked that AutoEventWireUp =false - still get the same error message. How can I resolve the 'Invalid Cast issue' as it is driving me NUTS!

pet.hen
  #5 (permalink)  
Old December 16th, 2004, 10:54 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: Atlanta, Georgia, USA.
Posts: 917
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Are you using the code download, or your own code?
  #6 (permalink)  
Old January 12th, 2005, 05:11 PM
Registered User
 
Join Date: Jan 2005
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to swingtipshoes Send a message via Yahoo to swingtipshoes
Default

I need to authorize the user (check in what groups he belongs to) from the Global.asax.cs file, under event:
Application_AuthorizeRequest(object sender, EventArgs e)

I get a invalid cast when I try to cast the Context.User from this location.

Any suggestions?

  #7 (permalink)  
Old January 15th, 2005, 11:49 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: Atlanta, Georgia, USA.
Posts: 917
Thanks: 0
Thanked 0 Times in 0 Posts
Default

You must not be using ThePhile if you're authorizing users there. That's not what the book suggests. You can't change the security model with re-designing the base class.

Eric
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
MyAccount.aspx Error coolnetboy BOOK: ASP.NET Website Programming Problem-Design-Solution 5 June 15th, 2006 05:51 AM
Problem: 'Sign Out' on "MyAccount.aspx" reidcor BOOK: ASP.NET Website Programming Problem-Design-Solution 4 April 11th, 2005 11:22 AM
MyAccount.aspx : can't modify email address Gjerstad BOOK: ASP.NET Website Programming Problem-Design-Solution 5 September 17th, 2003 01:52 PM
invalid cast exception giulio_santorini C# 2 August 21st, 2003 08:04 AM
exiting MyAccount.aspx robert BOOK: ASP.NET Website Programming Problem-Design-Solution 2 July 17th, 2003 11:23 AM



All times are GMT -4. The time now is 12:39 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.