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
|