|
 |
aspdotnet_website_programming thread: Re: System.InvalidCastException: Specified cast is not valid.
Message #1 by "Scott Willsey" <hangtown@t...> on Mon, 6 Jan 2003 12:23:59
|
|
Okay, I got it... First, make sure your page with the error inherits from
Wrox.ThePhile.Web.PhilePage (the base page class).
Now, in that base page class, find the method PhilePage_Load and change
the declaration from "private void PhilePage_Load" to "protected void
PhilePageLoad".
Now in your page with the error (which inherits from
Wrox.ThePhile.Web.PhilePage), add the following as the first line in your
Page_Load method:
base.PhilePage_Load(sender, e);
Recompile everything and go.
I would be happier if I could get the PhilePage_Load method to be called
automatically in the base page, which it is SUPPOSED to be, in their
OnInit method. But for some reason, it is not firing, or is firing after
the derived page's On_Load method is done. Not sure which at this point.
> Hi all,
> I am getting the following error while casting the Context.User to
S> itePrincipal in VB.NET.
> The code snippet is like this:
> Dim siteUser As CACI.WebModules.Accounts.Business.SitePrincipal
> siteUser = CType(Context.User, SitePrincipal)
> The SitePrincipal is the same class as is there in the ASP.NET website
p> rogramming book.
> Any help would be greatly appreciated.
A> shwini
Message #2 by "Scott Willsey" <hangtown@t...> on Mon, 6 Jan 2003 12:35:04
|
|
To add to my previous message... I took the code in the base page for
replacing the Context.User with our own custom one OUT of PhilePage_Load
and made a new method in the base page:
protected void PhilePage_LoadUser()
{
if (Context.User.Identity.IsAuthenticated)
{
// replace asp.net's default context user with
our own
SitePrincipal newUser = new SitePrincipal
(Context.User.Identity.Name);
Context.User = newUser;
}
}
Then in the base page's OnInit method, I changed it to:
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
this.PhilePage_LoadUser();
this.Error += new System.EventHandler(this.PhilePage_Error);
}
Now all you have to do is inherit your page from the base page, and you
can use the code they used, including the casting of Context.User to
SitePrincipal (or PhilePrincipal, as they originally called it in the C#
book).
>
O> kay, I got it... First, make sure your page with the error inherits
from
W> rox.ThePhile.Web.PhilePage (the base page class).
> Now, in that base page class, find the method PhilePage_Load and change
t> he declaration from "private void PhilePage_Load" to "protected void
P> hilePageLoad".
> Now in your page with the error (which inherits from
W> rox.ThePhile.Web.PhilePage), add the following as the first line in
your
P> age_Load method:
> base.PhilePage_Load(sender, e);
> Recompile everything and go.
> I would be happier if I could get the PhilePage_Load method to be
called
a> utomatically in the base page, which it is SUPPOSED to be, in their
O> nInit method. But for some reason, it is not firing, or is firing
after
t> he derived page's On_Load method is done. Not sure which at this point.
>
> > Hi all,
> > I am getting the following error while casting the Context.User to
S> > itePrincipal in VB.NET.
> > The code snippet is like this:
> > Dim siteUser As CACI.WebModules.Accounts.Business.SitePrincipal
> > siteUser = CType(Context.User, SitePrincipal)
> > The SitePrincipal is the same class as is there in the ASP.NET
website
p> > rogramming book.
> > Any help would be greatly appreciated.
A> > shwini
|
|
 |