不能创建在C文件:\\的Inetpub \\ wwwroot的编程 [英] Can't create a file in C:\inetpub\wwwroot programmatically

查看:388
本文介绍了不能创建在C文件:\\的Inetpub \\ wwwroot的编程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在创建一个文件中的ASP.NET网页背后的code函数,然后用一个JavaScript命令打开它。这部作品在IDE - 它创建的文件,问我在哪里,我要保存的文件,我可以将它保存,等等 - 但是当我安装网站并测试它,我得到,而只是想创建一个该UnauthorizedAccessException对于C之内的文件目录:\\的Inetpub \\ wwwroot文件

令人沮丧的是,我有一个服务运行类似的功能,并且其创建的目录和文件用C就好了:\\的Inetpub \\ wwwroot文件

我将不得不做的就是这一个网页工作?

 如果(!Directory.Exists(目录))
 {
      Directory.CreateDirectory(目录);
 } StreamWriter的SW =新的StreamWriter(完整路径,假的,Encoding.Uni code); SW.WriteLine(/ * *的东西/); SW.Close();


解决方案

您需要确保在.NET的用户有写的目录通过右键单击访问,将安全选项卡,并添加适当的用户和检查写复选框。

根据您的.NET / Windows的/ IIS的版本可以是不同的,通常是网​​络服务 IUSR 。如果您运行的IIS7请务必检查下的应用程序池的高级设置标识,因为这将是一个需要写访问权限的用户,通常又是这个网络服务。

I have a function in the code behind of an ASP.NET webpage that creates a file and then opens it with a javascript command. This works in the IDE - it creates the file, asks me where I want to save the file, I can save it, etc. - but when I install the website and test it out, I get an UnauthorizedAccessException while just trying to create the directory for the file within C:\inetpub\wwwroot.

The frustrating part is that I have a similar function that runs in a service and that creates its directories and files just fine in C:\inetpub\wwwroot.

What would I have to do to get this to work for a webpage?

 if(!Directory.Exists(directory))
 {
      Directory.CreateDirectory(directory);
 }

 StreamWriter SW = new StreamWriter(fullpath, false, Encoding.Unicode);

 SW.WriteLine(/*stuff*/);

 SW.Close();

解决方案

You need to make sure the .NET user has write access by right-clicking on the directory, going to the security tab, and adding the appropriate user and checking the write checkbox.

Depending on your version of .NET/Windows/IIS this can be different, typically it is Network Service or IUSR. If you are running IIS7 make sure to check the Identity under advanced settings of the application pool, as that will be the user that needs the write access, again typically this is Network Service.

这篇关于不能创建在C文件:\\的Inetpub \\ wwwroot的编程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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