Wednesday, 15 September 2010

c# - Temporarily disable impersonation in ASP -



c# - Temporarily disable impersonation in ASP -

i'm coding intranet scheme writes files locally webserver, through script using adodb.stream. problem is, uses logged windows/ad user business relationship so, impersonation activated default in iis - , need activated of time. since don't want give write access webserver needs create utilize of system, need temporarily "unimpersonate" session "iusr" account.

how that? preferentially in classic asp, whole site coded in it, in asp.net (c#) too.

i work big company, , access iis command panel/server machine bit limited (need deal department). , can't install custom modules or dlls either.

in past i've used msxml2.serverxmlhttp create server-side phone call switches impersonation context using http authorization headers. allows me create file using different context website running in.

class="lang-vb prettyprint-override">sub executecontext(url, data, user, password) dim http set http = server.createobject("msxml2.serverxmlhttp") response.charset = "utf-8" phone call http.open("post", url, false, user, password) 'called using basic authentication (not secure windows authenticated should adequate) phone call http.setrequestheader("authorization", "basic " & base64encode(user & ":" & password)) phone call http.setrequestheader("content-type", "application/x-www-form-urlencoded") phone call http.send(data) end sub 'supporting functions base64 encoded authorization header. function base64encode(indata) 'ripped from: 'http://www.pstruh.cz/tips/detpg_base64encode.htm 'rfc1521 '2001 antonin foller, pstruh software, http://pstruh.cz const base64 = _ "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz0123456789+/" dim sout, 'for each grouping of 3 bytes = 1 len(indata) step 3 dim ngroup, pout 'create 1 long 3 bytes. ngroup = &h10000 * asc(mid(indata, i, 1)) + _ &h100 * myasc(mid(indata, + 1, 1)) + _ myasc(mid(indata, + 2, 1)) 'oct splits long 8 groups 3 bits ngroup = oct(ngroup) 'add leading zeros ngroup = string(8 - len(ngroup), "0") & ngroup 'convert base64 pout = mid(base64, clng("&o" & mid(ngroup, 1, 2)) + 1, 1) + _ mid(base64, clng("&o" & mid(ngroup, 3, 2)) + 1, 1) + _ mid(base64, clng("&o" & mid(ngroup, 5, 2)) + 1, 1) + _ mid(base64, clng("&o" & mid(ngroup, 7, 2)) + 1, 1) 'add part output string sout = sout + pout next select case len(indata) mod 3 case 1: '8 bit final sout = left(sout, len(sout) - 2) + "==" case 2: '16 bit final sout = left(sout, len(sout) - 1) + "=" end select base64encode = sout end function function myasc(onechar) if onechar = "" myasc = 0 else myasc = asc(onechar) end function

this approach extremely flexible, in implementation utilize alter context in same page posting different data.

c# asp.net iis asp-classic impersonation

No comments:

Post a Comment