Unable to programmatically access the network path through VPN

I am trying to use a network path (create directory, write and read files) from a web service in ASP.NET.

Everything works fine from my office where the network path is on the same local network of my laptop, but when I try to connect to the network path via VPN, the directory creation fails with "Path access denied" error.

The weird thing is that from Windows Explorer I can access such a path given my VPN credentials that I saved in my Windows credentials wallet.

I also tried to set the IIS Application Pool ID to "Network Service" but no luck.

Can you help me?

Many thanks

EDIT:

When I try to execute a statement like

Directory.CreateDirectory(@"\\my\network\path");

      

from a simple console app project in my Visual Studio 2010 it works fine and a directory is created.

The problem is when I end up in an expression like this inside the business logic of my web service, which is running under local IIS (and to which I am connected via the Attach Process debug tool ... in VS2010)

+3


source to share


2 answers


It looks like when you are working locally, your local domain account is the context in which everything is done. When launching a console application, it is still running under your custom context from when the application was launched. When working in IIS, you are correct that the application pool account is being used and the networkervice account has some rather low privileges.

Instead of using a high-priority account (like yours), would issuing impersonation solve your problem? Any work that needs to be done over the VPN can get wrapped up in the context of the permissions. Here's another SO article on using impersonation that I've applied for related things:

How do you do impersonation in .NET?



See Matt Johnson's answer where he creates a custom impersonation class. Use this in a used block and then do your networking stuff. It uses advapi32.dll file with p / invoke to create this kind of voodoo user account. He also put together a NuGet package that can save you some time:

https://www.nuget.org/packages/SimpleImpersonation

+1


source


I may not have all the details of what you are asking directly, but if you are using this service through Visual Studio and VPN, have a look at this great article in CodeBetter.

runas /netonly /user:domain\username "C:\ProgramFiles\Path\to\your\visualstudio"

      



I don't have a computer that I have on in front of me, but I remember that I created a batch file and ran it to run VS and Sql Server Management Studio and it works like a charm.

If I misunderstood the problem, sorry for the noise.

0


source







All Articles