Re: (CustomIdentity)Thread.CurrentPrincipal.Identity - Cast not Va

From: Dominick Baier [DevelopMentor] (dbaier_at_pleasepleasenospamdevelop.com)
Date: 09/19/05


Date: Mon, 19 Sep 2005 12:01:09 -0700

Hello John,

WinForms works totally different than ASP.NET.

In ASP.NET you have to set the principal on each request. So after you set
it (besides that this code won't work correctly at all in ASP.NET) - you
redirect to to session.aspx - this gets served by a different thread - and
your principal is lost

You should use forms authentication and handle the Authenticate_Request.

Have you had a look at Forms Authentication before?

---------------------------------------
Dominick Baier - DevelopMentor
http://www.leastprivilege.com

> ----Logon.aspx-------------
> //SET Thread.CurrentPrincipal
> CustomIdentity id = new CustomIdentity(userTable);
> CustomPrincipal p = new CustomPrincipal(id,roles);
> System.AppDomain.CurrentDomain.SetThreadPrincipal(p);
> Response.Redirect("SessionInfo", true);
> ----SessionInfo.aspx-------
> //GET Thread.CurrentPrincipal
> private void Page_Load(object sender, System.EventArgs e)
> {
> CustomPrincipal p = (CustomPrincipal)(Thread.CurrentPrincipal);
> CustomIdentity id = (CustomIdentity)p.Identity; //INVALID CAST ERROR
> }
> If I use a GenericPrincipal and GenericIdentity it works fine.
> As soon as I use my CustomPrincipal and CustomIdentity it fails (in
> asp.net
> only)
> The same code, same class used by a test WinForms app works fine.



Relevant Pages

  • Winform Application Authentication into Sharepoint Site
    ... Does anybody know if its possible to autheticate using windows ... authentication from a Winforms Application into a Sharepoint Site. ...
    (microsoft.public.sharepoint.windowsservices)
  • Passport Authentication WinForms
    ... i wanted to know whether one could use Passport ... Authentication in WinForms (i know its possible in ... WebForms and ASP.NET) ...
    (microsoft.public.dotnet.framework.aspnet.security)