简体   繁体   English

通过运行asp.net mvc Web应用程序的IIS访问映射驱动器

[英]Access mapped drive by IIS running asp.net mvc web application

I have deployed an asp.net mvc web application on IIS 8 server inside an virtual machine (Windows server 2012 R2). 我在虚拟机(Windows Server 2012 R2)中的IIS 8服务器上部署了一个asp.net mvc Web应用程序。 An azure file storage is mapped as network drive in this virtual machine Windows server 2012 R2. 在此虚拟机Windows Server 2012 R2中,azure文件存储被映射为网络驱动器。 Now my asp.net mvc web application needs to read the files and folders of this mapped drive by C# System.IO code. 现在我的asp.net mvc Web应用程序需要通过C#System.IO代码读取此映射驱动器的文件和文件夹。 By default IIS is not allowed to access mapped drives. 默认情况下,不允许IIS访问映射的驱动器。

That's why the web application is throwing System.IO exception 这就是Web应用程序抛出System.IO异常的原因

"Could not find the specified path Z:\\" “找不到指定的路径Z:\\”

. I also tried to pass "\\\\\\\\{storage-name}.file.core.windows.net\\\\{fileshare-name} but still no success. 我也尝试传递"\\\\\\\\{storage-name}.file.core.windows.net\\\\{fileshare-name}但仍未成功。

Can some one guide me with correct configurations and settings which I should do inside IIS and web application? 有人可以指导我在IIS和Web应用程序中进行正确的配置和设置吗?

Finally, I succeeded to access the mapped network drive through IIS Server. 最后,我成功通过IIS服务器访问映射的网络驱动器。 I performed following steps. 我执行了以下步骤。

  • Create a new user account on VM. 在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. 借助Map network drive ..选项连接网络驱动
  • Open IIS Manager window, go to Application Pools 打开IIS管理器窗口,转到应用程序池
  • 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. 选择Web应用程序正在使用的应用程序池(在我的示例中,它是DefaultAppPool ,然后从右侧窗格单击Advanced Settings ...)
  • Change the Identity for this application pool with newly created user account name and password. 使用新创建的用户帐户名和密码更改此应用程序池的标识
  • Set Load User Profile to true . 加载用户配置文件设置为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 . 现在选择Default We Site下的Web应用程序。
  • 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). 单击“ 连接为...”按钮并选择“ 特定用户”单选按钮,然后使用此新创建的用户名(存储帐户名)和密码(存​​储帐户密钥)设置凭据。

That's it. 而已。 Now you can simply write standard C# IO code to access the directory and files of mapped drive. 现在您可以简单地编写标准C#IO代码来访问映射驱动器的目录和文件。 Here is a sample example. 这是一个示例示例。

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

Make sure that you access the files and folders by UNC path format only, just like I have done in above code. 确保您只能通过UNC路径格式访问文件和文件夹,就像我在上面的代码中所做的那样。

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

相关问题 从 IIS 运行 ASP.NET MVC 6 Web API - Running ASP.NET MVC 6 Web API from IIS 在IIS 6上运行的ASP.NET MVC 3应用程序上处理404 - Handling 404's on an ASP.NET MVC 3 application running on IIS 6 运行 exe 的 ASP.NET Web 应用程序在 VS 中工作,而不是在 IIS 中 - ASP.NET Web application running an exe works in VS, not in IIS ASP.NET MVC Web应用程序未在IIS Express 10.0中定义的端口上运行 - asp.net mvc web app is not running on defined port in IIS express 10.0 使用IIS7通过c#/ asp.net网页访问虚拟目录(映射驱动器) - Accessing virtual directory(mapped drive) via c#/asp.net webpage with IIS7 如何通过ASP.NET MVC 4 Web应用程序远程重置IIS /运行批处理文件? - How does one Reset IIS/Run Batch files via an ASP.NET MVC 4 Web Application Remotely? 当ASP.net MVC应用程序添加到IIS中的现有网站时,相对URL断开 - Relative URLs broken when ASP.net MVC application added to existing web site in IIS ASP.NET应用程序的Web安装程序在运行IIS7的计算机上失败 - Web Installer for an ASP.NET application failing on machines running IIS7 可扩展的ASP.NET MVC Web应用程序 - Extensible ASP.NET MVC Web Application 使用 ASP.NET MVC web 应用程序 - Using ASP.NET MVC web application
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM