Iprincipal & IIdentity problem

Ask a Question related to ASP.NET Security, Design and Development.

  1. #1

    Default Iprincipal & IIdentity problem

    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",pri ncipal);

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

    What could be wrong?

    Regards
    Aneesh A.V


    aneesh Guest

  2. Similar Questions and Discussions

    1. Customer IPrincial and IIdentity
      Hi, I need to push some more information than just username and roles in the IPrincipal implementation. For this, I wrote the following code...
    2. Custom IPrincipal and declarative security checking
      download http://www.pluralsight.com/toolcontent/show_pipeline.zip put the ashx file in a web app and run it through your browser - you'll see the...
    3. Marshaling IIdentity via web services.
      Is there a way to marshal an object via a web service that implements IIdentity? Thanks
    4. how to add another property to class inheriting from IIdentity?
      Hello peoples this is a question regarding security of windows application I want to add another property (the UserID) to...
    5. IPrincipal
      Anyone work with the IPrincipal object in an ASP.NET web app? Just wondering how it is used and if there are any best practice documents anyone is...
  3. #2

    Default Re: Iprincipal & IIdentity problem

    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
    [url]http://staff.develop.com/ballen[/url]


    > 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",pri ncipal);
    >
    > Now I want that Context.User = Tenprincipal to work.
    >
    > What could be wrong?
    >
    > Regards
    > Aneesh A.V


    Brock Allen Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139