I have an mvc3 app which I want to write to a file but don't know how.
IIS doesn't allow StreamWriter file = new StreamWriter(Environment.CurrentDirectory);
How do I go about writing to a file?
问题:
回答1:
IIS doesn't allow StreamWriter file = new StreamWriter(Environment.CurrentDirectory);
IIS allows everything. The account you are running your application under probably doesn't have permissions to write to this directory. So all you need to do is grant write permissions to this account to the specified directory. Alternatively you could write to the ~/App_Data
folder of your application where chances are that the account will have permission.
回答2:
You need to create a directory somewhere -- not necessarily within the InetPub -- and grant write rights for that directory to the Windows account that your Web application runs under.
So suppose your application runs in an Application Pool that is executed under the MyApplicationUser
account. Then you would create a directory, say D:\Writeable\MyApplication
and grant MyApplicationUser
write rights to that directory in Windows.
IIS has no control over that directory, only Windows does, so that is the only place where you need to grant the write rights.