Re: Urgent: Problem with custom 'Security.Principal.IPrincipal' implementation
From: Chris Lewis (chris.lewis@-nospam-exentra.no.spam.thanks.co.uk)
Date: 09/24/02
- Next message: Sitaraman: "Re: Problem with the Initialization Vector (IV)"
- Previous message: kulwant: "Security Exception"
- In reply to: Sitaraman: "Re: Urgent: Problem with custom 'Security.Principal.IPrincipal' implementation"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]
From: "Chris Lewis" <chris.lewis@-nospam-exentra.no.spam.thanks.co.uk> Date: Tue, 24 Sep 2002 11:46:56 +0100
looks interesting, thanks...
"Sitaraman" <l.sitaraman@verizon.net> wrote in message
news:#OTh6N2YCHA.1636@tkmsftngp09...
> Take a look at this
> http://www.csharphelp.com/archives/archive203.html
>
> Sitaraman
>
> "Chris Lewis" <chris.lewis@-nospam-exentra.no.spam.thanks.co.uk> wrote in
> message news:3d8ef115$0$1293$cc9e4d1f@news.dial.pipex.com...
> > I have a very frustrating and urgent problem that seems to have arisen
> from
> > nowhere, and which I cannot figure out.
> >
> > I am using Forms authentication, and have a non-secured root directory
and
> a
> > 'Secure' subdirectory (amongst others).
> >
> > I have a custom implementation classes for the
> > 'Security.Principal.IPrincipal' and 'Security.Principal.IIdentity'
> > interfaces - called SitePrincipal and SiteIdentity respectively.
> >
> > The following code is from my 'Login' button event handler:
> >
> > *** code ***
> > SitePrincipal newUser = m_userManager.AuthenticateUser(
> > UsernameTextBox.Text, PasswordTextBox.Text);
> > if (newUser == null)
> > {
> > OutputLabel.Text = "Login failed for " + UsernameTextBox.Text;
> > OutputLabel.Visible = true;
> > }
> > else
> > {
> > Context.User = newUser;
> > FormsAuthentication.SetAuthCookie( UsernameTextBox.Text, false);
> >
> >
> Response.Redirect(FormsAuthentication.GetRedirectUrl(UsernameTextBox.Text,
> > false));
> > }
> >
> > *** end code ***
> >
> > So I am setting Context.User = newUser, where newUser is an instance of
> > SitePrincipal - my custom implementation of IPrincipal.
> >
> > The following is the code-behind from the target page of the redirect,
and
> > is where the problem arises:
> >
> > *** code ***
> > if (!Context.User.Identity.IsAuthenticated )
> > {
> > // if not, redirect to the Login page
> > Response.Redirect("blah.aspx", true);
> > }
> >
> > if (!IsPostBack)
> > {
> > SitePrincipal userPrincipal = (SitePrincipal)Context.User;
> > SiteIdentity userIdentity = (SiteIdentity)userPrincipal.Identity;
> >
> > // Other stuff...
> > }
> > *** end code ***
> >
> > The problem is that the object stored in Context.User is an instance of
> > 'GenericPrincipal' and cannot be cast to SitePrincipal - so the error I
> get
> > is an 'InvalidCastException'!!!! Somewhere along the line, my
> SitePrincipal
> > has been down-cast to a GenericPrincipal...???!!!
> >
> > I know that I have had this code working fine in the past! Please, if
> anyone
> > can help it would be much appreciated.
> >
> > Chris Lewis
> >
> >
> >
>
>
- Next message: Sitaraman: "Re: Problem with the Initialization Vector (IV)"
- Previous message: kulwant: "Security Exception"
- In reply to: Sitaraman: "Re: Urgent: Problem with custom 'Security.Principal.IPrincipal' implementation"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]