473,395 Members | 1,464 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,395 software developers and data experts.

Web Service, StreamWriter and System.UnauthorizedAccessException.

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.UnauthorizedAccessException: Access to
'C:\WINDOWS\system32\TestOut.txt' denied.
in System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
in System.IO.FileStream.Init(String path, FileMode mode, FileAccess
access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize,
FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean
bFromProxy)
in System.IO.FileStream..ctor(String path, FileMode mode, FileAccess
access, FileShare share, Int32 bufferSize, FileOptions options)
in System.IO.StreamWriter.CreateFile(String path, Boolean append)
in System.IO.StreamWriter..ctor(String path, Boolean append, Encoding
encoding, Int32 bufferSize)
in System.IO.StreamWriter..ctor(String path)
in WS.HelloWorldWS.HelloWorld()
The code contained in Test.asmx is this:

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

using System.IO;
using System.Web.Services;

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

I get this exception:

System.UnauthorizedAccessException: Access to
'C:\WINDOWS\system32\TestOut.txt' denied.
That file is being written to the C:\Windows\System32 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.HelloWorldWS" %>

using System.IO;
using System.Web.Services;

namespace WS
{
[WebService(Namespace="http://microsoft.com/webservices/")]
public class HelloWorldWS: WebService
{
[WebMethod]
public string HelloWorld()
{
using(StreamWriter sw = new StreamWriter("TestOut.txt"))
{
sw.WriteLine("Hello 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.UnauthorizedAccessException: Access to
'C:\WINDOWS\system32\TestOut.txt' denied.
using(StreamWriter sw = new StreamWriter("TestOut.txt"))
Try:

using(StreamWriter sw = new StreamWriter(Server.MapPath("TestOut.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
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...
1
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...
2
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...
4
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...
0
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...
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...
2
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...
4
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...
2
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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...

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.