1

having a big of an issue with with Server.MapPath in that I can't get it to resolve from server and unsure how to test what it's trying to do.

Locally, it works fine in a whole variety of different ways, but when I put it up to the server, each and everyone one of them fails.

string filename = "TestLog.txt";
string path = Path.Combine(Server.MapPath("~/Content/"), filename);
Debug.WriteLine(path)

using (System.IO.StreamWriter writer = new System.IO.StreamWriter(path, true))
{
    writer.WriteLine(message);
    writer.Close();
}

I've tried /content in the path and adding the extra / into the filename. Have tried with and without the tilda. They all resolve the path correctly locally but not on the server.

For the record, the path I am trying to access is

Local: C:\Users\username\Documents\MyWebSite\Web\Content\TestLog.txt Server: D:\Web\MyWebSite\Content\TestLog.txt

With MyWebSite\Web being the root of the site locally MyWebSite being the root on server, so mywebsite.com/content/TestLog.txt

Any help at all is greatly appreciated.

Kezia
  • 99
  • 10

1 Answers1

1

It's going to be a permissions thing.

When you are running locally (under Cassini WebServer...part of Visual Studio), you've got permission.

When you are hosting in IIS, you probably don't.

Give "write" permission to that folder - all depends on version of IIS you are using how you do it - might be via an ApplicationPool.

How do I give ASP.NET permission to write to a folder in Windows 7?

IIS7 folder permissions for web application

Community
  • 1
  • 1
Colin Smith
  • 11,811
  • 4
  • 34
  • 44