473,320 Members | 1,580 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Web Service can't write to c:\windows\system32???

I'm trying to write a web service which, when run, writes a line to a file on
the web server. I've created one under IIS and the method I'm calling looks
like this...

[WebMethod]
public string HelloWorld()
{
try
{
//Server.MapPath("testfile.txt");
StreamWriter fileStream = new StreamWriter("testfile.txt", false);
fileStream.WriteLine("Testing Testing Testing!");
fileStream.Flush();
fileStream.Close();
}
catch(Exception ex)
{
return ("Error: " + ex);
}
return "Hello World";
}

But when I compile and run this in VS .NET I get the following output...

<?xml version="1.0" encoding="utf-8" ?>
<string xmlns="http://tempuri.org/">Error:
System.UnauthorizedAccessException: Access to the path
"C:\WINDOWS\system32\testfile.txt" is denied. at
System.IO.__Error.WinIOError(Int32 errorCode, String str) at
System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access,
FileShare share, Int32 bufferSize, Boolean useAsync, String msgPath, Boolean
bFromProxy) at System.IO.FileStream..ctor(String path, FileMode mode,
FileAccess access, FileShare share, Int32 bufferSize) at
System.IO.StreamWriter.CreateFile(String path, Boolean append) at
System.IO.StreamWriter..ctor(String path, Boolean append, Encoding encoding,
Int32 bufferSize) at System.IO.StreamWriter..ctor(String path, Boolean
append) at CPWebService.Service1.HelloWorld() in
c:\inetpub\wwwroot\cpwebservice\service1.asmx.cs:l ine 61</string>

Why is it trying to write to System32? And why wont it work? I've tried
setting the ASP .NET user account to Administrator and I've tried changing
all the Runtime Security Policies in the .NET Configuration in Administrative
Tools to Full Trust (yes I know how bad this is but I will sort that out
later) but I still get the same message.

Just in case it makes a difference. I'm running IIS on Windows XP
Professional with SP2.

Any ideas?

Darrell

Nov 16 '05 #1
1 3161
redneon <re*****@discussions.microsoft.com> wrote:
I'm trying to write a web service which, when run, writes a line to a file on
the web server. I've created one under IIS and the method I'm calling looks
like this...

[WebMethod]
public string HelloWorld()
{
try
{
//Server.MapPath("testfile.txt");
StreamWriter fileStream = new StreamWriter("testfile.txt", false);
fileStream.WriteLine("Testing Testing Testing!");
fileStream.Flush();
fileStream.Close();
}
catch(Exception ex)
{
return ("Error: " + ex);
}
return "Hello World";
}

But when I compile and run this in VS .NET I get the following output...
<snip>
Why is it trying to write to System32?
Because that's the working directory of the process, I suspect.
And why wont it work?


Don't try to get it to work. Change where it's writing to. You don't
*really* want to write to System32, do you? That's unspeakably nasty.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Fabio Papa | last post by:
I am trying to write a windows service that sends emails to clients at specific times based on information in a sql db. Since this is done for multiple cities, I start a thread for each city and...
3
by: Glenn Venzke | last post by:
I'd like to write a windows service. Unfortunately, my company would only spring for the standard edition of VB.NET which doesn't support the creation of windows services. Is it possible to write one...
5
by: John | last post by:
Hi I am trying to get web reference to my first (!) web service which is on a remote host. I am getting the following error; Server Error in '/' Application. Runtime Error Description: An...
6
by: acool | last post by:
I managed to get my VB.NET service installed. Now I can't get it to do anything. Tell me how do you debug smething like this if you have to manually install the assembly to run it? the same code...
3
by: Amjad | last post by:
Hi, I just wrote a test Windows Service that creates a text file on startup (please see my code below). The file is never created. Protected Overrides Sub OnStart(ByVal args() As String) Dim...
27
by: pisquem | last post by:
I am building an windows service that is to be deployed on a windows server 2003 and I want to have activity written to the event log, I want its own log called ('CustomLog') Below is what I...
7
by: shai | last post by:
I am working at .net 1.1, writing in c#. I have windows service with a COM object. Every unexpected time The COM object throw an error that make my service get stuck (do not respond). I can catch...
3
dmjpro
by: dmjpro | last post by:
plz send me a good link which can clearify me how the J2EE framework works i want the details information .... plz help thanx
0
by: JohnP | last post by:
Hi all Does anyone know the best way to get feedback from a Windows Service? I have written a Windows service which uses a class library (a DLL) which has a timer which does some operations...
0
by: hepsubah | last post by:
I'm trying to capture a client cert in my ASP.NET application, and use that cert as the client cert for a call to secure web service. I've used the following code, but am getting a 403 error on...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.