通过运行asp.net mvc Web应用程序的IIS访问映射驱动器 [英] Access mapped drive by IIS running asp.net mvc web application

查看:110
本文介绍了通过运行asp.net mvc Web应用程序的IIS访问映射驱动器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在虚拟机(Windows server 2012 R2)中的IIS 8服务器上部署了一个asp.net mvc Web应用程序。
在此虚拟机Windows Server 2012 R2中,azure文件存储被映射为网络驱动器。
现在我的asp.net mvc Web应用程序需要通过C#System.IO代码读取此映射驱动器的文件和文件夹。默认情况下,IIS不允许访问映射驱动器。

I have deployed an asp.net mvc web application on IIS 8 server inside an virtual machine (Windows server 2012 R2). An azure file storage is mapped as network drive in this virtual machine Windows server 2012 R2. Now my asp.net mvc web application needs to read the files and folders of this mapped drive by C# System.IO code. By default IIS is not allowed to access mapped drives.

这就是Web应用程序抛出System.IO异常的原因

That's why the web application is throwing System.IO exception

找不到指定的路径Z:\

"Could not find the specified path Z:\"

。我还尝试传递\\\\ {storage-name} .file.core.windows.net \\ {fileshare-name}
但仍然没有成功。

. I also tried to pass "\\\\{storage-name}.file.core.windows.net\\{fileshare-name} but still no success.

有人可以指导我在IIS和Web应用程序中进行正确的配置和设置吗?

Can some one guide me with correct configurations and settings which I should do inside IIS and web application?

推荐答案

最后,我成功通过IIS服务器访问了映射的网络驱动器。
我执行了以下步骤。

Finally, I succeeded to access the mapped network drive through IIS Server. I performed following steps.


  • 在VM上创建一个新用户帐户。

  • 此新帐户的用户名将是存储帐户名

  • 此用户的密码为存储帐户密钥,以==结尾

  • 创建后此新用户帐户我将此用户的帐户类型更改为管理员

  • 转到我的电脑此电脑

  • 借助映射网络驱动器附加网络驱动器.. 选项。

  • 打开IIS管理器窗口,转到应用程序池

  • 选择正在使用的应用程序池通过您的Web应用程序(在我的情况下,它是 DefaultAppPool 并从右侧窗格中单击高级设置...

  • 更改此应用程序池的标识,包含新创建的用户帐户名和密码。

  • 加载用户个人资料设置为 true

  • 点击确定保存更改。

  • 点击右侧窗格中的回收链接刷新选择的应用程序池。

  • 现在选择默认我们网站下的网络应用程序。

  • 点击基本设置... 打开编辑网站对话框。

  • 确保应用程序池名称正确无误。

  • 点击连接为... 按钮并选择特定用户单选按钮,然后使用此新创建的用户名(存储帐户名称)和密码(存​​储帐户密钥)设置凭据。

  • Create a new user account on VM.
  • The user name for this new account will be the Storage Account Name
  • The password for this user will be Storage account key which ends with "=="
  • After creating this new user account I changed the account type for this user to Administrator
  • Go to My Computer OR This PC
  • Attach the network drive with the help of Map network drive.. option.
  • Open IIS Manager window, go to Application Pools
  • Select the application pool which is being used by your web application (in my case it was DefaultAppPool and click on Advanced Settings... from right side pane.
  • Change the Identity for this application pool with newly created user account name and password.
  • Set Load User Profile to true.
  • Click OK to save changes.
  • Click on Recycle link from right side pane to refresh the selected application pool.
  • Now select your web application which is under Default We Site.
  • Click on Basic Settings... to open Edit Site dialog box.
  • Make sure that the Application Pool name is correct.
  • Click on Connect as... button and select Specific user radio button and then set the credentials with this newly created User name (Storage account name) and password (Storage account key).

就是这样。现在您可以简单地编写标准C#IO代码来访问映射驱动器的目录和文件。下面是一个示例示例。

That's it. Now you can simply write standard C# IO code to access the directory and files of mapped drive. Here is a sample example.

var allDirs = Directory.GetDirectories("\\\\<storageaccountname>.file.core.windows.net\\<storagefileshare>");
ViewBag.Items = allDirs;

确保只通过UNC路径格式访问文件和文件夹,就像我在上面的代码。

Make sure that you access the files and folders by UNC path format only, just like I have done in above code.

这篇关于通过运行asp.net mvc Web应用程序的IIS访问映射驱动器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆