Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Security > Why i cannot write a file, even i add a permission to that file.

Reply
Thread Tools

Why i cannot write a file, even i add a permission to that file.

 
 
Umut Tezduyar
Guest
Posts: n/a
 
      11-12-2004
My web site user should change some files in the root folder. Why the
following code is not working.
I dont want to manually give permission for the asp.net account for each
file. Instead, i want to give permission that the caller can write to the
specified file.
I have investigated the msdn and web. Is this information is hidden ?? Can
any one help me about this.

string path = System.Web.HttpContext.Current.Server.MapPath(stri ng.Empty) +
@"\";

string file = path + this.insertedcontrolName;

// Enable write permission for the file.

FileIOPermission fileIOPerm1 = new
FileIOPermission(FileIOPermissionAccess.AllAccess, file);

fileIOPerm1.AddPathList(FileIOPermissionAccess.Wri te, path);

fileIOPerm1.AddPathList(FileIOPermissionAccess.Rea d, path);

fileIOPerm1.Assert ();

// Writing to the file

TextWriter writer = new System.IO.StreamWriter (file, false,
System.Text.Encoding.UTF;

writer.Write (this.html);

writer.Close ();


 
Reply With Quote
 
 
 
 
Steven Cheng[MSFT]
Guest
Posts: n/a
 
      11-13-2004
Hi Umut,

Thanks for your posting. As for the file permission problem you mentioned,
are you got the "Access denied" error? In fact, this problem is caused by
the windows's file access premission rather than the .NET's CAS. So setting
the

FileIOPermission fileIOPerm1 = new
FileIOPermission(FileIOPermissionAccess.AllAccess, file);

is not necessary. We need to grant the NTFS's file access permission(
write/modify) of that file to the asp.net 's worker process account( the
machine\aspnet on WIN2K IIS 5 or the NetworkService on win2k3 iis6). After
that, you can get your page write/modify the file correctly.

Hope helps. If you still have anything unclear, please feel free to post
here. Thanks.'

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)




 
Reply With Quote
 
 
 
 
Umut Tezduyar
Guest
Posts: n/a
 
      11-13-2004
This is not solving my problem. I have developed a control and i want my
control to write some files in the web applications root.
Do i have to inform users, which will use my control, as add, a permission
to the each file that my application will use.
What if my user deploys its web site with my control to a server that he
cannot change the permission of the files.


"Steven Cheng[MSFT]" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> Hi Umut,
>
> Thanks for your posting. As for the file permission problem you mentioned,
> are you got the "Access denied" error? In fact, this problem is caused by
> the windows's file access premission rather than the .NET's CAS. So
> setting
> the
>
> FileIOPermission fileIOPerm1 = new
> FileIOPermission(FileIOPermissionAccess.AllAccess, file);
>
> is not necessary. We need to grant the NTFS's file access permission(
> write/modify) of that file to the asp.net 's worker process account( the
> machine\aspnet on WIN2K IIS 5 or the NetworkService on win2k3 iis6). After
> that, you can get your page write/modify the file correctly.
>
> Hope helps. If you still have anything unclear, please feel free to post
> here. Thanks.'
>
> Regards,
>
> Steven Cheng
> Microsoft Online Support
>
> Get Secure! www.microsoft.com/security
> (This posting is provided "AS IS", with no warranties, and confers no
> rights.)
>
>
>
>



 
Reply With Quote
 
Steven Cheng[MSFT]
Guest
Posts: n/a
 
      11-15-2004
Hi Umut,

Thanks for your response. The problem is that the file access protection is
the buildin security protection of the NTFS FILE SYSTEM. If you do want to
provide such permission for multi-user controls, one possbile approach is
to add a sub folder under the web application's root folder ( the VIRUTAL
DIR) and grant the write/modify permission of that folder to the asp.net
worker process account. Then we can put all your usercontrols that need
modify under that sub folder.

BTW, I still recommend that we don't modify the page or usercontrol's
source( aspx or ascx or code behind) at runtime. Because the web
application has the "numRecompilesBeforeAppRestart" setting which indicate
that the web app will be restarted when the number of the asp.net component
files be modified and recompiled has exceed this value, see the following
doc:

#<compilation> Element
http://msdn.microsoft.com/library/en...pilationSectio
n.asp?frame=true

So, I don't think modify the page/usercontrol source is a good means. Would
you consider putting the UserControl's UI change logic into the control's
code so as to make it output different content at runtime? For example, use
some properties to control the UserControl's output and we can set such
properties in Usercontrol's construct. If you have any other ideas or
concerns , please feel free to post here. Thanks.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

 
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
problem in running a basic code in python 3.3.0 that includes HTML file Satabdi Mukherjee Python 1 04-04-2013 07:48 PM
Why my working ps/2 mouse freezes and even don't even get recon.after reboot ? demi General Computer Support 0 08-03-2007 05:30 AM
Why my working ps/2 mouse freezes and even don't even get recon.after reboot ? demi General Computer Support 0 08-03-2007 05:28 AM
findcontrol("PlaceHolderPrice") why why why why why why why why why why why Mr. SweatyFinger ASP .Net 2 12-02-2006 03:46 PM
Even older fart, even newer newbie Stan Goodman Java 11 07-04-2003 07:32 AM



Advertisments