Wrox Programmer Forums
|
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
 
Old December 7th, 2004, 06:50 AM
Registered User
 
Join Date: Dec 2004
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

 
Old December 7th, 2004, 03:35 PM
Registered User
 
Join Date: Dec 2004
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
 
Old December 10th, 2004, 05:28 PM
Friend of Wrox
 
Join Date: Jun 2003
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
 
Old December 15th, 2004, 11:47 AM
Registered User
 
Join Date: Dec 2004
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
 
Old December 16th, 2004, 10:54 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 917
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Are you using the code download, or your own code?
 
Old January 12th, 2005, 05:11 PM
Registered User
 
Join Date: Jan 2005
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?

 
Old January 15th, 2005, 11:49 PM
Friend of Wrox
 
Join Date: Jun 2003
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





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





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