简体   繁体   English

无法通过VPN以编程方式访问网络路径

[英]Cannot programmatically access network path through VPN

I'm trying to use a network path (create directory, write and read files) from a Web Service in ASP.NET. 我正在尝试从ASP.NET中的Web服务使用网络路径(创建目录,写入和读取文件)。

Everything works fine from my office where the network path is in the same LAN of my laptop, but when I try to connect to the network path through a VPN, the creation of a directory fails with "Access to path is denied" error. 我的办公室里的一切工作正常,网络路径位于我的笔记本电脑的同一个局域网中,但是当我尝试通过VPN连接到网络路径时,目录的创建失败并显示“访问路径被拒绝”错误。

The strange thing is that from Windows Explorer I can perfectly access such path, given my VPN credentials, that I stored in Windows Credentials Wallet. 奇怪的是,从Windows资源管理器中,我可以完美地访问这样的路径,根据我的VPN凭据,我存储在Windows Credentials Wallet中。

I also tried to set my IIS App Pool Identity to 'Network Service' but no luck. 我还尝试将我的IIS应用程序池标识设置为“网络服务”,但没有运气。

Can you help me please? 你能帮我吗?

Thank you very much 非常感谢你

EDIT: 编辑:

When I try to execute a statement like 当我尝试执行类似的语句时

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

from a simple console application project in my Visual Studio 2010 it works perfectly and the directory is created. 从我的Visual Studio 2010中的一个简单的控制台应用程序项目,它完美地工作,并创建目录。

The problem is when I hit such a statement inside the business logic of my web service that is running under local IIS (and which I'm connected to via "Attach Process..." debug tool in VS2010) 问题是当我在我的Web服务的业务逻辑中发出这样的声明时,该声明在本地IIS下运行(并且我通过VS2010中的“Attach Process ...”调试工具连接到该声明)

Sounds like when you are running locally, your local domain account is the context under which everything is being ran. 听起来像在本地运行时,您的本地域帐户是运行所有内容的上下文。 When running the console app, it is still running under your user context since you initiated the application. 运行控制台应用程序时,自启动应用程序以来,它仍在用户上下文中运行。 When running in IIS, you are correct in that the app-pool account is being used, and the networkservice account has some pretty low privileges. 在IIS中运行时,您正确使用了应用程序池帐户,并且网络服务帐户具有一些非常低的权限。

Instead of using a highly privileged account (such as yours), would impersonation solve your issue? 而不是使用高权限帐户(例如您的帐户),模拟会解决您的问题吗? Any work that needs to be done over the VPN can "wrapped" in a context the appropriate permissions. 任何需要通过VPN完成的工作都可以在上下文中“包装”适当的权限。 Here is another SO article on using impersonation, which I have implemented for related things: 这是另一篇关于使用模拟的SO文章,我已经为相关事项实现了这个:

How do you do Impersonation in .NET? 你如何在.NET中进行模拟?

See Matt Johnson's answer where he creates a custom Impersonation class. 请参阅Matt Johnson的答案,他创建了一个自定义的Impersonation类。 Use that in a using block, then do your network stuff. 在使用块中使用它,然后做你的网络东西。 It uses the advapi32.dll with p/invoke to do this kind of user account voodoo. 它使用advapi32.dll和p / invoke来做这种用户帐户voodoo。 He put together a NuGet package as well which may save you some time: 他还整理了一个NuGet包,可以为您节省一些时间:

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

I may not have all the details of what you're asking straight, but if you're running this service via Visual Studio and VPN, take a look at this great article , at CodeBetter. 我可能没有详细了解您所要求的内容,但如果您通过Visual Studio和VPN运行此服务,请查看CodeBetter上的这篇精彩文章

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

I don't have the computer I have this on in front of me, but I recall that I created a batch file and ran it to start VS and Sql Server Management Studio, and it works like a charm. 我没有在我面前的计算机,但我记得我创建了一个批处理文件并运行它来启动VS和Sql Server Management Studio,它就像一个魅力。

If I've misunderstood the issue, sorry for the noise. 如果我误解了这个问题,请为噪音感到抱歉。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM