Web Service, StreamWriter and System.UnauthorizedAccessException.

B

BLUE

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.
 
M

Mr. Arnold

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.
 
?

=?ISO-8859-1?Q?Arne_Vajh=F8j?=

BLUE said:
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
 
B

BLUE

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top