Unable to write file from ASPX page. What am I missing?

G

Gregory Gadow

I have a folder on \\webserver\wwwroot, called staticContent. The folder
has several message of the day text files, such as RepMotd.text. I have
an admin page, AdminMotd.aspx, that allows a user to view and edit the
contents of the files.

Webserver is running Win Server 2003 64-bit and IIS 6.0. The development
machine is Win XP, using Visual Studio 2005 (thus ASP.Net 2.0.)

In IIS, staticContent folder has Write checked and execute permission is
set to Script Only . In NTSF, the folder grants full permissions to
Network System.

When I try to overwrite an existing file in \staticContent, or try to
create a new file, I get a System.UnauthorizedAccessException. The
Application error log on \\webserver notes that the error is on the page
I am trying to run, that my user name is what I logged in as, that I am
authenticated, and that the thread account name is NT AUTHORITY\NETWORK
SYSTEM. Elsewhere, I am able to read these same files and insert them
dynamically into the web page.

This is the code that I am trying to run in AdminMotd.aspx, cut down to
the basics. If it makes any difference, the code is run "in page" and
not as part of a separate code-behind file.

******************
<script runat="server">
Protected Sub MotdChange(ByVal ThisFile As String, ByVal ThisText As
String)
Dim sw As StreamWriter = New StreamWriter(StaticRoot + ThisFile,
False)
sw.Write(ThisText)
sw.Close()
End Sub

Protected Sub RepMotdChange_Click(Byval sender As Object, ByVal e As
System.EventArgs)
MotdChange("RepMotd.text", RepMotdText.Text)
End Sub
</script>

<asp:Content ...>
<asp:TextBox ID="RepMotdText" runat="server"></asp:TextBox>
<asp:Button ID="RepMotdChange" runat="server" />
</asp:Content>
********************

I have traced that the error occurs when New StreamWriter is called,
rather than when actually trying to write to the file. Obviously I'm
missing something, but danged if I can find it. Any suggestions?
 
B

Bob Barrows [MVP]

There was no way for you to know it (except maybe by browsing through
some
of the previous questions before posting yours - always a recommended
practice), but this is a classic asp newsgroup.
ASP.Net is a different technology from classic ASP.
While you may be lucky enough to find a dotnet-savvy person here who
can
answer your question, you can eliminate the luck factor by posting your
question to a newsgroup where the dotnet-savvy people hang out. I
suggest
microsoft.public.dotnet.framework.aspnet.
 
B

Bob Barrows [MVP]

Bob said:
There was no way for you to know it (except maybe by browsing through
some
of the previous questions before posting yours - always a recommended
practice), but this is a classic asp newsgroup.
ASP.Net is a different technology from classic ASP.
While you may be lucky enough to find a dotnet-savvy person here who
can
answer your question, you can eliminate the luck factor by posting
your question to a newsgroup where the dotnet-savvy people hang out. I
suggest
microsoft.public.dotnet.framework.aspnet.
Oops! I did not realize he had crossposted this group. I saw and
responded to the message in .inetserver.asp
 
B

Bob Barrows [MVP]

Please remove .inetserver.asp.general from the crosspost when replying
to this.
Thanks
 

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

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,070
Latest member
BiogenixGummies

Latest Threads

Top