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 August 15th, 2006, 06:35 PM
Authorized User
 
Join Date: Jun 2004
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default SitePrinciple and SiteIdentity casting problems

I'm working on a project that I've adapted from this book, but I'm getting cast errors for my implementation of IIdentity and IPrincipal.

One such error is:

Unable to cast object of type 'System.Security.Principal.GenericPrincipal' to type 'AlfordDocs.WebModules.Accounts.Business.SitePrinc ipal'.

Which occurs when I do:

        If CType(Context.User, SitePrincipal).HasPermission( _
        CInt(ContentPermissions.CreatePages)) _
        AndAlso TypeOf Context.User Is SitePrincipal Then
        'bla bla bla
        End If

Another such error is:

Unable to cast object of type 'System.Web.Security.FormsIdentity' to type 'AlfordDocs.WebModules.Accounts.Business.SiteIdent ity

Which occurs when running this line of code:

        If Context.User.Identity.IsAuthenticated Then
            Dim id As SiteIdentity = CType(Context.User.Identity, SiteIdentity)
            UserName.Text = id.UserName
        Else
            Response.Redirect("/WebModules/Accounts/?Forward=" & Request.FilePath)
        End If


However, I get no errors at all in my SiteHeader.ascx control, when I execute the following code:

        UserGreetingListItem.InnerHtml = "Welcome"

        If Context.User.Identity.IsAuthenticated Then

            Dim id As SiteIdentity = CType(Context.User.Identity, SiteIdentity)
            UserGreetingListItem.InnerHtml = UserGreetingListItem.InnerHtml _
            & ", <strong>" & id.UserName & "</strong>!"
        Else
            UserGreetingListItem.InnerHtml = UserGreetingListItem.InnerHtml _
            & ", <strong>guest</strong>!"
        End If


This seems crazy. There is very little difference between the code fragments. I'd like to know why the first two throw cast errors but the last one doesn't, and where I should look to fix the problem.

Does anybody have any ideas please?

Many thanks
Ben

 
Old August 15th, 2006, 11:35 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 917
Thanks: 0
Thanked 0 Times in 0 Posts
Default

You likely missed some of the obvious differences, like the folders and whether you have any old assemblies lying around. It's easy to see this kind of issue on systems that haven't had much housecleaning. And it's hard to research because you have a lot of bin folders.

The 2005 model is cleaner, where any custom security code can go in the app_code folder. But you often don't need custom security code in 2005 with simple sites.

Eric

 
Old August 16th, 2006, 05:48 AM
Authorized User
 
Join Date: Jun 2004
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Englere,

Thanks for your response, but I'm not sure I understand it. Are you saying that it's not a problem with my code at all, but an issue with different versions of ASP .NET? I really wasn't expecting that at all, but if you think that's the most likely cause, could you please tell me more specifically what "differences" I'm looking for, and what the differences are between, as I'm not sure I follow your train of thought.

Many thanks
Ben

 
Old August 21st, 2006, 10:47 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 917
Thanks: 0
Thanked 0 Times in 0 Posts
Default

You need to understand how .net loads assemblies because you're probably not loading the assemlies you think you're loading. Which ones you think it's loading?

You need to get real familiar with your directories and what's in them. Make sure that anything old has been removed. I advise NOT having any of these assemblies in the GAC because that would just complicate updates and not really help you.

This type of issue is almost always caused by stale files lying around. Especially since you've done some custom modifications - are you sure that the original assemblies are gone? It's time to become a Windows Explorer power guru!

Eric







Similar Threads
Thread Thread Starter Forum Replies Last Post
Casting pfrigo BOOK: Professional .NET 2.0 Generics 3 November 19th, 2007 04:49 PM
Casting - Can you help koco C# 1 September 24th, 2007 08:41 AM
Casting Problem liorlankri ASP.NET 1.x and 2.0 Application Design 2 January 2nd, 2007 03:31 AM
casting ravibodani Access 1 April 4th, 2006 01:19 PM
SiteIdentity TypeCasting Problem RM82 BOOK: ASP.NET Website Programming Problem-Design-Solution 3 September 17th, 2005 10:38 AM





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