IIS下访问网络驱动器(网络位置)

System.Diagnostics.Process p = new System.Diagnostics.Process();
            p.StartInfo.FileName = "cmd.exe";
            p.StartInfo.UseShellExecute = false;    //是否使用操作系统shell启动
            p.StartInfo.RedirectStandardInput = true;//接受来自调用程序的输入信息
            p.StartInfo.RedirectStandardOutput = true;//由调用程序获取输出信息
            p.StartInfo.RedirectStandardError = true;//重定向标准错误输出
            p.StartInfo.CreateNoWindow = true;//不显示程序窗口
            p.Start();//启动程序

            p.StandardInput.WriteLine(string.Format(@"net use z: {0} guest /user:guest&&exit", path));

            string output = p.StandardOutput.ReadToEnd();
            p.WaitForExit();
            p.Close();

开始没有注意到IIS的用户与开发时IISExpress并不一致。开发时,先把盘挂载到了系统中,直接访问z盘,看起来并没有问题。实际运行时,同样挂载到了系统,但IIS的用户无法访问。

解决:需要在代码中进行挂载,最简单的就是调用cmd执行net use来挂载。

PS:其实就是要用IIS的用户来挂载,这样它才能访问到,代码中不处理的话,应该也可以直接在cmd进到IIS使用的用户来挂载。

posted on 2016-10-11 09:38  阿呜的边城  阅读(1808)  评论(0编辑  收藏  举报

导航