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("t estfile.txt", false);
fileStream.Writ eLine("Testing Testing Testing!");
fileStream.Flus h();
fileStream.Clos e();
}
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.Unauthor izedAccessExcep tion: Access to the path
"C:\WINDOWS\sys tem32\testfile. txt" is denied. at
System.IO.__Err or.WinIOError(I nt32 errorCode, String str) at
System.IO.FileS tream..ctor(Str ing path, FileMode mode, FileAccess access,
FileShare share, Int32 bufferSize, Boolean useAsync, String msgPath, Boolean
bFromProxy) at System.IO.FileS tream..ctor(Str ing path, FileMode mode,
FileAccess access, FileShare share, Int32 bufferSize) at
System.IO.Strea mWriter.CreateF ile(String path, Boolean append) at
System.IO.Strea mWriter..ctor(S tring path, Boolean append, Encoding encoding,
Int32 bufferSize) at System.IO.Strea mWriter..ctor(S tring path, Boolean
append) at CPWebService.Se rvice1.HelloWor ld() in
c:\inetpub\wwwr oot\cpwebservic e\service1.asmx .cs:line 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 1 3195
redneon <re*****@discus sions.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("t estfile.txt", false); fileStream.Writ eLine("Testing Testing Testing!"); fileStream.Flus h(); fileStream.Clos e(); } 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.co m> http://www.pobox.com/~skeet
If replying to the group, please do not mail me too This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 continue the processing
from each thread. My service starts fine (gives me no errors, etc), but it
doesn't seem to start the new threads. I am new to windows services, so I
don't know if I'm doing something wrong. Should I maybe be doing this...
|
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 manually? If not, are there any other (cheaper) tools available? Any free ones?
|
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 application error occurred on the server. The current custom
error settings for this application prevent the details of the application
|
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 works just fine in a
VB form but when I initiallize with the WS OnStart event I get nothing. Any
help is greatly appreciated.
TB
|
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 swLog As StreamWriter = File.CreateText("C:\myLog.txt")
swLog.WriteLine("My Windows Service has just started.")
swLog.Close() : swLog.Flush()
End Sub
| |
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 have so far...its builds fine but when I go to start
the service i get the following error.
---------------------------
Services
---------------------------
|
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 this error.
I want to restart my windows service every time the COM object throws an
error.
I use System.ServiceProcess.ServiceController to stop and start my service.
But there is one thing I do not understand:
|
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
|
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 every <xseconds.
I'd like to be able to somehow get the current 'elapsed' seconds of
the timer, with a view to displaying something on the service control
manager program I have written.
All seems to be OK (service works properly, as does the DLL and...
|
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 the
invocation of the service. All the service is supposed to do is
return the subject of the passed cert (I'll do more with it later)
...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |