473,795 Members | 2,986 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Web Service, StreamWriter and System.Unauthor izedAccessExcep tion.

I've created a folder named TestDir in my wwwroot and I've created the
associated virtual application from IIS management snap-in.

I've given full control to TestDir to:
IUSR, ASPNET, Network service, Anonimous access, Everyone, Users, VS
Developers

I've set write access and low application protection from IIS management
snap-in.

Please help me because I'm going crazy!
I get this exception:

System.Unauthor izedAccessExcep tion: Access to
'C:\WINDOWS\sys tem32\TestOut.t xt' denied.
in System.IO.__Err or.WinIOError(I nt32 errorCode, String maybeFullPath)
in System.IO.FileS tream.Init(Stri ng path, FileMode mode, FileAccess
access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize,
FileOptions options, SECURITY_ATTRIB UTES secAttrs, String msgPath, Boolean
bFromProxy)
in System.IO.FileS tream..ctor(Str ing path, FileMode mode, FileAccess
access, FileShare share, Int32 bufferSize, FileOptions options)
in System.IO.Strea mWriter.CreateF ile(String path, Boolean append)
in System.IO.Strea mWriter..ctor(S tring path, Boolean append, Encoding
encoding, Int32 bufferSize)
in System.IO.Strea mWriter..ctor(S tring path)
in WS.HelloWorldWS .HelloWorld()
The code contained in Test.asmx is this:

<%@ WebService Language="C#" Class="WS.Hello WorldWS" %>

using System.IO;
using System.Web.Serv ices;

namespace WS
{
[WebService(Name space="http://microsoft.com/webservices/")]
public class HelloWorldWS: WebService
{
[WebMethod]
public string HelloWorld()
{
using(StreamWri ter sw = new StreamWriter("T estOut.txt"))
{
sw.WriteLine("H ello world");
return "Hello World";
}
}
}
}
Thanks,
Luigi.
Jun 10 '07 #1
3 9204
Please help me because I'm going crazy!
>

I get this exception:

System.Unauthor izedAccessExcep tion: Access to
'C:\WINDOWS\sys tem32\TestOut.t xt' denied.
That file is being written to the C:\Windows\Syst em32 directory. The very
HEART of the O/S. It should be denied.

>The code contained in Test.asmx is this:

<%@ WebService Language="C#" Class="WS.Hello WorldWS" %>

using System.IO;
using System.Web.Serv ices;

namespace WS
{
[WebService(Name space="http://microsoft.com/webservices/")]
public class HelloWorldWS: WebService
{
[WebMethod]
public string HelloWorld()
{
using(StreamWri ter sw = new StreamWriter("T estOut.txt"))
{
sw.WriteLine("H ello world");
return "Hello World";
}
}
}
}
You need to have a Web or App.config file that has the pathing to where
Testout.txt should be written and read that pathing from the config file.

Jun 10 '07 #2
BLUE wrote:
I've created a folder named TestDir in my wwwroot and I've created the
associated virtual application from IIS management snap-in.

I've given full control to TestDir to:
IUSR, ASPNET, Network service, Anonimous access, Everyone, Users, VS
Developers
System.Unauthor izedAccessExcep tion: Access to
'C:\WINDOWS\sys tem32\TestOut.t xt' denied.
using(StreamWri ter sw = new StreamWriter("T estOut.txt"))
Try:

using(StreamWri ter sw = new StreamWriter(Se rver.MapPath("T estOut.txt")))

Arne
Jun 10 '07 #3
Thank you so much!!!!!!

I thought the path was the asmx path; seeing that error I was wandering if I
had to use some ASP.Net directive but I have never used ASP.
Thank you very much, you have saved me!
Bye,
Luigi.
Jun 10 '07 #4

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

Similar topics

2
1188
by: gatekeeper | last post by:
Why could it be that i am able to use StreamWriter from a windows application but not from a web application? I am getting an unauthorizedaccessexception and the exception message is "Access to the path... is denied". the code i'm using is very straightforward: using System.IO; ....
1
3195
by: redneon | last post by:
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... public string HelloWorld() { try { //Server.MapPath("testfile.txt");
2
2385
by: Michael Huhn | last post by:
I have a WebForm with several File-Inputs. On the server side I loop through the Request.PostedFiles and call a .SaveAs to a specific subfolder of my web. I get a System.UnauthorizedAccessException for the folder but when I try to write a file with a StreamWriter, it works. Of course the folder has NTFS and IIS-Writing-permissions. What can I do???
4
2917
by: Bruce | last post by:
I am developing an ASP.NET web service application. It works fine on my WinXP Prof development machine. But when I send it to a Windows Server 2003 system I get the following error (attached below). I suppose I have some kind of permissions issue on the server? What recommendations can anyone propose? Thanks, -- Bruce
0
1668
by: Seth | last post by:
For some reason my service works fine except that it will create the file in my c drive, but will not write to the file. Sorry if this is a duplicate post, i have found some that ask the same question - but noone seems to answer. Do i need to do anything specific to write to a text file from a windows service, much appreciated.
3
14961
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
2
2438
by: stringy | last post by:
Why could it be that i am able to use StreamWriter from a windows application but not from a web application? I am getting an unauthorizedaccessexception and the exception message is "Access to the path... is denied". the code i'm using is very straightforward: using System.IO; .....
4
21766
by: carson | last post by:
I have written two windows services: - service A does some crunching of local data files and uploads them to a central processing computer via http. - service B monitors a manifest file on a webserver to see if service A needs to be updated. What service B does if it sees their is an update for service A is to download a new copy of the service A executable, stop service A, replace the executable with the new copy, and start service B...
2
3083
by: Andez | last post by:
I've wrote a windows service that performs simple functions within our application. To ensure safe running of the service - if it errors we want to know where when how - it logs to a text file - in this instance BLAH.log. The code is executed within a timer which runs at 30 second intervals and polls folders. Each part of the process will log to the log file. The service will throw an IOException exception. See below for this and my...
0
9672
marktang
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...
0
9519
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,...
0
10215
jinu1996
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...
0
10001
tracyyun
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...
0
9043
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7541
isladogs
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...
0
6783
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4113
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
3
2920
bsmnconsultancy
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...

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.