Wrox Programmer Forums
|
BOOK: ASP.NET Website Programming Problem-Design-Solution
This is the forum to discuss the Wrox book ASP.NET Website Programming: Problem - Design - Solution, Visual Basic .NET Edition by Marco Bellinaso, Kevin Hoffman; ISBN: 9780764543869
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: ASP.NET Website Programming Problem-Design-Solution section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 14th, 2004, 12:49 AM
Registered User
 
Join Date: Apr 2004
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Context User

Hi,

messed around with the IPrincipal and IIdentity a little bit. Threads on this indicate that this is a general issue. Here my contribution:

web.config contains this:
<authentication mode="Windows" />
<identity impersonate="true"
    userName="HansWurschd"
    password="HansWurschd" />
!!!! be sure to use asp_setreg in real life !!!!
<authorization>
  <deny users="?" />
  <allow users="*" />
</authorization>

In Global.asax put the following code:

protected void WindowsAuthentication_OnAuthenticate(object source , WindowsAuthenticationEventArgs e){
// fires on each Request and puts custom user in Context
e.User = new KLBPrincipal(e.Identity, "egon bahr");
}

Then you can Access the user as follows.

private void Button1_Click(object sender, System.EventArgs e) {
 if(Context.User.Identity.IsAuthenticated){
   // impersonated user
   Response.Write(WindowsIdentity.GetCurrent().Name + "<br>");
   // user, sitting in front of the box
   Response.Write("Context.User.Identity.Name " + Context.User.Identity.Name + "<br><br>");
  }
}

If it takes considerable time to rebuild your user, consider whether to put it into session state, get it lazy loading or to use some other "persistence" mechanism. Have a look on the UIP from Microsoft. Cool stuff!!!

HTH,
David






Similar Threads
Thread Thread Starter Forum Replies Last Post
Context.User.Identity.Name jimbeam36 BOOK: ASP.NET Website Programming Problem-Design-Solution 4 November 6th, 2004 06:33 AM
(SitePrincipal)Context.User Philey BOOK: ASP.NET Website Programming Problem-Design-Solution 3 October 8th, 2004 05:38 PM
Maintaining Context.User cjh301 BOOK: ASP.NET Website Programming Problem-Design-Solution 6 March 30th, 2004 04:50 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.