Iprincipal & IIdentity problem

Discussion in 'ASP .Net Security' started by aneesh, Apr 5, 2005.

  1. aneesh

    aneesh Guest

    HI All,
    I ma new to .NET. I was a java programmer for the past 2 years, and now
    shifted to .NET. My company (A product based company) is rewritng an existing
    portal produt from java to .NET, using c# and asp.NET. I ma into the
    authntication module of this particular development.

    I have developed some classes called TeNPrincipal wich impliments the
    IPrincipal and TeNIdentity which impliments the IIdentity, when I have a
    certain other properties for our portal user specific thing.

    Now after successfull authentication in the login.aspx.as codebehind, i set
    the formsauthcookie and create a new instance of the TeNprincipal and
    Tenidentoty and add this TeNIdentity to the TeNPrincipal.

    Now the next thing i do is do something like this:
    Context.User = newTeNPrincipal(Context.User.Identity, TeNSecurity.GetRoles());

    and redirects tothe desktop.aspx

    Now on the
    desktop.aspx when i try

    TeNPrincipal principal = (TeNPrincipal) HttpContext.curent.User;
    I get error invalid cast:
    And whne i chek the type of HttpContext.curent.User it shows GenericPrincipal)

    I also tried TeNPrincipal principal = (TeNPrincipal) Context.User;

    None worked. what could be wrong. for the timebeing, I made a wrapper class
    which returns and sets the TeNPrinicipla for the
    user(TeNSecurity.SetPrincipal(...) && TeNsecurity.GetPrincipal() will return
    the Ten principal where I am setting it something like this:
    HttpContext.Current.Session.Add("TENPRINCIPAL",principal);

    Now I want that Context.User = Tenprincipal to work.

    What could be wrong?

    Regards
    Aneesh A.V
     
    aneesh, Apr 5, 2005
    #1
    1. Advertising

  2. aneesh

    Brock Allen Guest

    You must reset the HttpContent.User on each request into the application.
    You should do this in global.asax (or in a HttpModule) in the Application_AuthenticateRequest
    event.

    -Brock
    DevelopMentor
    http://staff.develop.com/ballen



    > HI All,
    > I ma new to .NET. I was a java programmer for the past 2 years, and
    > now
    > shifted to .NET. My company (A product based company) is rewritng an
    > existing
    > portal produt from java to .NET, using c# and asp.NET. I ma into the
    > authntication module of this particular development.
    > I have developed some classes called TeNPrincipal wich impliments the
    > IPrincipal and TeNIdentity which impliments the IIdentity, when I have
    > a certain other properties for our portal user specific thing.
    >
    > Now after successfull authentication in the login.aspx.as codebehind,
    > i set the formsauthcookie and create a new instance of the
    > TeNprincipal and Tenidentoty and add this TeNIdentity to the
    > TeNPrincipal.
    >
    > Now the next thing i do is do something like this: Context.User =
    > newTeNPrincipal(Context.User.Identity, TeNSecurity.GetRoles());
    >
    > and redirects tothe desktop.aspx
    >
    > Now on the desktop.aspx when i try
    >
    > TeNPrincipal principal = (TeNPrincipal) HttpContext.curent.User;
    > I get error invalid cast:
    > And whne i chek the type of HttpContext.curent.User it shows
    > GenericPrincipal)
    > I also tried TeNPrincipal principal = (TeNPrincipal) Context.User;
    >
    > None worked. what could be wrong. for the timebeing, I made a wrapper
    > class which returns and sets the TeNPrinicipla for the
    > user(TeNSecurity.SetPrincipal(...) && TeNsecurity.GetPrincipal() will
    > return the Ten principal where I am setting it something like this:
    > HttpContext.Current.Session.Add("TENPRINCIPAL",principal);
    >
    > Now I want that Context.User = Tenprincipal to work.
    >
    > What could be wrong?
    >
    > Regards
    > Aneesh A.V
     
    Brock Allen, Apr 5, 2005
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Craig Buchanan

    IIdentity casting problem

    Craig Buchanan, Feb 24, 2004, in forum: ASP .Net
    Replies:
    4
    Views:
    996
    Craig Buchanan
    Feb 24, 2004
  2. Mike Taylor
    Replies:
    2
    Views:
    795
    Mike Taylor
    Jul 23, 2004
  3. CodeCowboy
    Replies:
    2
    Views:
    2,433
    CodeCowboy
    Feb 23, 2005
  4. sloan
    Replies:
    0
    Views:
    845
    sloan
    Jun 27, 2007
  5. Andrew Jocelyn
    Replies:
    6
    Views:
    2,666
    Allen Chen [MSFT]
    Feb 10, 2009
Loading...

Share This Page