Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Security > Writing a text file to the file system

Reply
Thread Tools

Writing a text file to the file system

 
 
cwbp
Guest
Posts: n/a
 
      03-21-2005
Using Visual Studio C#

When I ran the following code:

System.IO;

private void Button1_Click(object sender, System.EventArgs e)
{
//FileStream fs = File.Create(Server.MapPath("test.txt"));
FileStream fs = File.Create("C:\\MYSAVEDFILES\\test.txt");
StreamWriter sw = new StreamWriter(fs);
sw.Write(TextBox1.Text);
sw.Close();
fs.Close();

}

I initially got an error message that "access was denied." The message
suggested that I give ASP.NET user access rights/permissions to the folder.

I then [manually] gave the logged in user write permission to the folder.

Then, when I ran the above code, the text file was created.

Is there another way [i.e., programatically using C#] to allow my code to
write a text file to the file system without giving access rights to a user?
Can the permissions be given to the app [the code] instead of to a user?

Any suggestions would be appreciated.

Thanks.

bebop



 
Reply With Quote
 
 
 
 
Joe Kaplan \(MVP - ADSI\)
Guest
Posts: n/a
 
      03-22-2005
Are you using impersonation in your application? The app should use the
ASP.NET process account's credentials unless you are impersonating.

If there is confusion, always check the value of
System.Security.Principal.WindowsIdentity.GetCurre nt().Name.

It is also possible to impersonate in code or move the file writing code to
a COM+ component running under a different identity, but that probably isn't
needed here.

Joe K.

"cwbp" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Using Visual Studio C#
>
> When I ran the following code:
>
> System.IO;
>
> private void Button1_Click(object sender, System.EventArgs e)
> {
> //FileStream fs = File.Create(Server.MapPath("test.txt"));
> FileStream fs = File.Create("C:\\MYSAVEDFILES\\test.txt");
> StreamWriter sw = new StreamWriter(fs);
> sw.Write(TextBox1.Text);
> sw.Close();
> fs.Close();
>
> }
>
> I initially got an error message that "access was denied." The message
> suggested that I give ASP.NET user access rights/permissions to the
> folder.
>
> I then [manually] gave the logged in user write permission to the folder.
>
> Then, when I ran the above code, the text file was created.
>
> Is there another way [i.e., programatically using C#] to allow my code to
> write a text file to the file system without giving access rights to a
> user?
> Can the permissions be given to the app [the code] instead of to a user?
>
> Any suggestions would be appreciated.
>
> Thanks.
>
> bebop
>
>
>



 
Reply With Quote
 
 
 
 
M
Guest
Posts: n/a
 
      03-22-2005
>> ASP.NET process account's

Could you explain exactly how one uses this. How does one get get his hands
on this, programatically?

Thanks.



"Joe Kaplan (MVP - ADSI)" wrote:

> Are you using impersonation in your application? The app should use the
> ASP.NET process account's credentials unless you are impersonating.
>
> If there is confusion, always check the value of
> System.Security.Principal.WindowsIdentity.GetCurre nt().Name.
>
> It is also possible to impersonate in code or move the file writing code to
> a COM+ component running under a different identity, but that probably isn't
> needed here.
>
> Joe K.
>
> "cwbp" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > Using Visual Studio C#
> >
> > When I ran the following code:
> >
> > System.IO;
> >
> > private void Button1_Click(object sender, System.EventArgs e)
> > {
> > //FileStream fs = File.Create(Server.MapPath("test.txt"));
> > FileStream fs = File.Create("C:\\MYSAVEDFILES\\test.txt");
> > StreamWriter sw = new StreamWriter(fs);
> > sw.Write(TextBox1.Text);
> > sw.Close();
> > fs.Close();
> >
> > }
> >
> > I initially got an error message that "access was denied." The message
> > suggested that I give ASP.NET user access rights/permissions to the
> > folder.
> >
> > I then [manually] gave the logged in user write permission to the folder.
> >
> > Then, when I ran the above code, the text file was created.
> >
> > Is there another way [i.e., programatically using C#] to allow my code to
> > write a text file to the file system without giving access rights to a
> > user?
> > Can the permissions be given to the app [the code] instead of to a user?
> >
> > Any suggestions would be appreciated.
> >
> > Thanks.
> >
> > bebop
> >
> >
> >

>
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
ASP.NET form action file - writing to text file icedragon ASP .Net 0 07-13-2010 01:48 PM
Writing a text file to the file system =?Utf-8?B?Y3dicDE1?= ASP .Net 5 10-29-2005 10:39 AM
Writing a text file to the file system =?Utf-8?B?Y3dicA==?= ASP .Net 0 03-21-2005 11:09 PM
Any problems with writing the information into a file - Multi-users perform writing the same file at the same time ???? HNguyen ASP .Net 4 12-21-2004 01:53 PM
Question: Writing text file based TestBenches vs. Waveform file based simulation. BLF VHDL 4 08-07-2004 12:44 AM



Advertisments