Link to home
Start Free TrialLog in
Avatar of DFPITC
DFPITCFlag for Australia

asked on

Problems reading UNC paths from impersonated asp.net using vb

Basically, i'm trying to write a file to people's home directory using VB/ASP.NET

I run this code:
(note: M_Util.Debug_Write is a function that writes to a file I can tail/read)
Dim wi As WindowsIdentity = CType(User.Identity, WindowsIdentity)
M_Util.Debug_Write(wi.GetCurrent().Name)
M_Util.Debug_Write(System.Threading.Thread.CurrentPrincipal.Identity.Name)
Dim wic As WindowsImpersonationContext = wi.Impersonate()
M_Util.Debug_Write(wi.GetCurrent().Name)
M_Util.Debug_Write(System.Threading.Thread.CurrentPrincipal.Identity.Name)
M_Util.Debug_Write(Directory.Exists(Server.MapPath("/"))) 'Web server app root
M_Util.Debug_Write(Directory.Exists("C:\")) 'web server c
M_Util.Debug_Write(Directory.Exists("\\myfileserver\transit")) 'transit drive share
M_Util.Debug_Write(Directory.Exists("\\10.0.0.40\transit")) 'transit drive share (by ip)
M_Util.Debug_Write(Directory.Exists("\\10.0.0.40\transit\test")) 'transit drive folder (by ip)
M_Util.Debug_Write(Directory.Exists("\\mypc\c$")) 'my pc
M_Util.Debug_Write(Directory.Exists("\\10.0.0.51\c$"))'my pc (ip)
wic.Undo()
M_Util.Debug_Write(wi.GetCurrent().Name)
M_Util.Debug_Write(System.Threading.Thread.CurrentPrincipal.Identity.Name)

Open in new window

and it outputs this:
"NT AUTHORITY\NETWORK SERVICE"
"MYDOMAIN\myuser"
"MYDOMAIN\myuser"
"MYDOMAIN\myuser"
"True"
"True"
"False"
"False"
"False"
"False"
"False"
"NT AUTHORITY\NETWORK SERVICE"
"MYDOMAIN\myuser"

Open in new window

Avatar of DFPITC
DFPITC
Flag of Australia image

ASKER

it's worth also noting that i've tried just writing to a text file in all those locations just in case it was the Directory.Exists command

No luck of course
ASKER CERTIFIED SOLUTION
Avatar of Nasir Razzaq
Nasir Razzaq
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of DFPITC

ASKER

This answered my question:
http://forums.asp.net/p/1347272/2756134.aspx

Basically, the impersonation only works when using it on the webserver.