An ASP.NET Question (or Two)
This one will be sent around the newsgroups and all other relevant places. This is more of an intranet-centric question for those who are not swimming in SharePoint: when <identity impersonate="true" />
is declared in your web.config
, do blocks like these become irrelevant:WindowsIdentity id = (WindowsIdentity)p.Identity;
WindowsImpersonationContext wic = id.Impersonate();
try { //do stuff… }
finally { wic.Undo(); wic.Dispose(); } //?This leads to a nested question, is it cool to do this:using( WindowsImpersonationContext wic = id.Impersonate() )
{ //do stuff… } //?
My concern is that the Undo()
method will not be called in the using
block. I could run some hokey tests (with WindowsIdentity.GetCurrent()
) to indirectly determine that something happened but… anyway…
My problem is that the WindowsImpersonationContext
block does not seem to work when the ‘stuff’ to be done is writing a file to the browser. Only when <identity impersonate="true" />
is declared are files written correctly.
This leads to another nested question, what is the difference between Response.TransmitFile()
and Response.WriteFile()
?
You can see a lot of questions here. In order to reduce confusion in the newsgroup world, it is best not to ask all of these questions at once—so bundling them all here for future reference will help.