Re: Urgent: Problem with custom 'Security.Principal.IPrincipal' implementation
From: Sitaraman (l.sitaraman@verizon.net)
Date: 09/24/02
- Next message: Joseph: "RSA encryption using OAEP padding"
- Previous message: Kipp Hawley: "Re: SSL - https or http"
- In reply to: Chris Lewis: "Urgent: Problem with custom 'Security.Principal.IPrincipal' implementation"
- Next in thread: Chris Lewis: "Re: Urgent: Problem with custom 'Security.Principal.IPrincipal' implementation"
- Reply: Chris Lewis: "Re: Urgent: Problem with custom 'Security.Principal.IPrincipal' implementation"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]
From: "Sitaraman" <l.sitaraman@verizon.net> Date: Mon, 23 Sep 2002 20:45:27 -0400
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: Joseph: "RSA encryption using OAEP padding"
- Previous message: Kipp Hawley: "Re: SSL - https or http"
- In reply to: Chris Lewis: "Urgent: Problem with custom 'Security.Principal.IPrincipal' implementation"
- Next in thread: Chris Lewis: "Re: Urgent: Problem with custom 'Security.Principal.IPrincipal' implementation"
- Reply: Chris Lewis: "Re: Urgent: Problem with custom 'Security.Principal.IPrincipal' implementation"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]