CodeVerge.Net Beta


   Explore    Item Entry    Members      Register  Login  
NEWSGROUP
.NET
Algorithms-Data Structures
Asp.Net
C Plus Plus
CSharp
Database
HTML
Javascript
Linq
Other
Regular Expressions
VB.Net
XML

Free Download:




Zone: > NEWSGROUP > Asp.Net Forum > general_asp.net.security Tags:
Item Type: NewsGroup Date Entered: 1/6/2008 2:16:00 AM Date Modified: Subscribers: 0 Subscribe Alert
Rate It:
(NR, 0)
XPoints: N/A Replies: 1 Views: 36 Favorited: 0 Favorite
Can Reply:  No Members Can Edit: No Online: Yes
2 Items, 1 Pages 1 |< << Go >> >|
Liming
Asp.Net User
Thread.CurrentPrincipal exists only for one page?1/6/2008 2:16:00 AM

0/0

Hello all,

I think I misunderstood what  the "Thread.CurrentPrincipal" is,  could somebody help me with it?

Currently, we are using forms authentication by default and for a new client, we are try to integrate it with a third party Authentication schemes (SiteMinder - which checks for HttpHeader variable). After some research, we find the best place to do it is in "Application_PostAuthenticateRequest" of Global.asax.  Naturally, since we are there, we want to use a Custom Principal object that wraps around the default FormsIdentity element and store a "UserInfo" object along with it. This way, the "UserInfo" object can be queried out of the Custom Principal throughout the application without the need to hit the database again. (At least that's what my original intention was)

So here is what I'm confused with.  Upon the first page loads, I hit database, get user information back, set it to a "UserInfo" object, attach it to my custom principal object "MyCustomPrincicpal",set "Thread.CurrentPrincipal = MyCustomPrincipal" and I was able to get "MyCustomPrincipal" object back on a page. No problem. But if I go to another page, the same process happened all over again!! At the beginning of any page load, Thread.CurrentPrincpal is never "MyCustomPrinciapl", so I'm seeing a database hit on every single page.

Is that how Thread.CurrentPrincipal works? How do you persist the logged User information object (which contains 2 other sub List<objects>") without hitting the database more than 1 time using Custom Principal?

I think I got the concept wrong.

Here is a snippet

 void Application_PostAuthenticateRequest(Object sender, EventArgs e)
 {

        if (HttpContext.Current.User != null)
        {
                  if (HttpContext.Current.User.Identity.IsAuthenticated)
                  {

                           if (HttpContext.Current.User is MyCustomPrincicpal)
                           { 

                                          //do nothing
                           }
                           else{

                                  // Assuming it's the first time, then MyCustomPrincipal should be set.

                                   FormsIdentity id = (FormsIdentity)HttpContext.Current.User.Identity;
                                   String name = id.Name ;

                                   //Query db and get back UserInfo and Roles
                                   UserInfo  userInfo = blah;

                                   MyCustomPrincicpal customPrincipal = new MyCustomPrincicpal(id,roles,userinfo);
                                   Thread.CurrentPrincpal = customPrincipal;

                           }

                }
       }
 }
 


Liming Xu
Jumptree ASP.NET 2.0 Project Management - For the Open Source Community and Effectively Manage Projects/Tasks/Milestones
mkamoski
Asp.Net User
Re: Thread.CurrentPrincipal exists only for one page?1/6/2008 2:45:01 AM

0/0

Here are some hints that might help; but, I do not have a detailed answer.

These articles are a little old, but I used them with .NET 2 and it worked great. 

How To: Implement IPrincipal 

http://msdn2.microsoft.com/en-us/library/aa302401.aspx

How To: Create GenericPrincipal Objects with Forms Authentication

http://msdn2.microsoft.com/en-us/library/aa302399.aspx 

How To: Use Forms Authentication with SQL Server

http://msdn2.microsoft.com/en-us/library/aa302398.aspx 

Follow that code and it does work-- it did for me.

(Caveat-- Things may be different in Framework 3.5; I do not know yet.)

HTH.

Thank you.

-- Mark Kamoski 


http://www.WebLogicArts.com
2 Items, 1 Pages 1 |< << Go >> >|


Free Download:

Books:
Professional ASP.NET 2.0 Security, Membership, and Role Management Authors: Stefan Schackow, Pages: 611, Published: 2006
Building Secure Microsoft ASP.NET Applications: Authentication, Authorization, and Secure Communication : Patterns & Practices Authors: Microsoft Corporation Staff, Drew Bird, Microsoft Corporation, Microsoft Corporation, Danielle Voeller Bird, Pages: 586, Published: 2003
Expert C# 2005 Business Objects Authors: Rockford Lhotka, Pages: 668, Published: 2006
Application Development Using Visual Basic and .NET Authors: Robert J. Oberg, Peter Thorsteinson, Dana L. Wyatt, Pages: 830, Published: 2002

Web:
VFPConversion Article: Compare Interfaces and Polymorphism in VFP ... One of the first examples presented in this article uses the Thread. ... CurrentPrincipal only returns useful information if a user is logged into the ...
Authentication problem Only Integrated Windiows Authentication is active. What is the problem? ... Thread.CurrentPrincipal.Identit y.AuthenticationType.ToString ...
Page 4 - Apply Single-Sign-On to Your Application Handles MyBase.Load Dim p As WindowsPrincipal = Thread.CurrentPrincipal .... ' Check here - Should only return ONE result For i = 0 To SearchResult. ...
when CurrentPrincipal is set in async call back, NET 2.0 loses ... Thread.CurrentPrincipal = null; This is bug or not. I do not know. Only thing that i know is that there exists a tedious difference on ...
submit age - ng.asp-net-forum.security - Fix error problem @CodeVerge thread.currentprincipal exists only for one page? ... Cheats for PC. ... submit one of the codes below to enable that particular cheat code for Age of . ...
CSLA .NET 20 VB Errata If Thread.CurrentPrincipal.Identity.IsAuthenticated Then pnlUser. ... of the page, second line, the phrase "specified rule exists" should read "specified ...
Adventures of an aspiring agile developer in a not-quite agile world Only post one photo per day (fotolog). Ended up with average of 11 comments/ photo .... Thread.CurrentPrincipal = originalPrincipal; }. readonly string name; ...
Walkthrough: Implementing a Pluggable SSO Provider Because only one SSO provider can be in use at a time, it is recommended you ... Thread.CurrentPrincipal). The following code shows the implementation of ...
Re: Windows Identity simple question ???? Jun 6, 2007 ... if you look at Thread.CurrentPrincipal.Identity in the debugger ... use the method you sugest otherwise I will only get the user which ...
.NET Security Now, when you extract the current principal from Thread and examine the iden- ... However, this code requires that the only one who can run this code is an ...




Search This Site:










help on scheduler (aspnet_wp.exe unhandled error)

let me try before i buy

shopping cart needed

asp.net configuration manager add user error

helps with datarelations with data access application block.

stepping through code in debug

can't localize default.master

how do i call an existing .aspx page from within dnn 3.0.12

send database info to email

user defined table problem

payment gateway

how to preserve the variable value?? plz help

vb2k8 import problem in asp.net page

how to include htm files, etc, using vb.net / asp.net standard edition?

visual web developer installer is extremly slow

i need a function!!

problem with master page

i am new to asp.net

web service limitation ?

client-side caching of htc files

using a contect page to view a classic asp page?

department based child portals

regex again

dnn portability issue

multiple role/membership providers - creating and accessing them dynamically

error in passing values between pages

login page, logout after 3 attempts

additional steps after authentication

storing fields in variables

how to compile a aspx.vb script

 
All Times Are GMT