tags:

views:

32

answers:

3

Hello I am using asp.net 3.5. And i am serializing an object in server, I rent a hosting and i want to modify something in a dinamic way with XML,

This is my code :

Stream writer = new FileStream(Environment.CurrentDirectory + @"\public_html\" + nombrearchivo.Text, FileMode.Create);

serializer.Serialize(writer, p);

this is my error massage:

Exception Details: System.UnauthorizedAccessException: Access to the path 'C:\Windows\SysWOW64\inetsrv\dasd.xml' is denied.

Thanks!!

A: 

The answer is in the error message: "access denied"

You do not have write permissions to that folder, which makes perfect sense; you shouldn't have write permission to that folder, at least you likely shouldn't.

If you need to cache something for later use, either use session for temporary storage, or talk to your hosting company about getting write permission for longer-term storage.

Randolpho
But he's *not* writing to that folder (at least given the code he gave us).
Kirk Woll
@Kirk Woll `serializer.Serialize(writer, p);` ?
BioBuckyBall
But the path for that writer contains "\public_html\", no? And the error in the exception does not include that folder.
Kirk Woll
A: 

Environment.CurrentDirectory is a per process property that most likely is not the directory you want; in this case, it is the directory in which the IIS worker process is launched.

In any case, for typical ASP.Net hosting (as opposed to physical or virtual server hosting), you will be restricted by Code Access Security policy as well as the rights of the IUSR account that the IIS worker process runs as; typically this means very minimal privileges so as to attempt to limit the damage of a compromised or malicious web page script, usually significantly less than the privileges of your application-uploading login.

In short, you will need to arrange for an application-writable directory (and likely greater than medium ASP.Net trust as well) if you want to save files.

Jeffrey Hantin
A: 

Hello all! I discover that the problem was the path...

"\hmfsw\web\DTCWIN107\MYSITE.com\public_html\"

Worked fine! after asked the hosting provider 8 times they could tell me the right one

Thanks you very Much!!

nicolas