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

Ask a Question related to ASP.NET Security, Design and Development.

  1. #1

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

    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.UTF8);

    writer.Write (this.html);

    writer.Close ();


    Umut Tezduyar Guest

  2. Similar Questions and Discussions

    1. write value from flash file to an external file
      how can I write value from flash file to an external file like (text file or xml file)
    2. advice needed... cf write data to xml file for use in flash app thatuses xml file
      I'm wondering if it is possible to use CF to: 1) connect to existing db; 2) get specific data from table; 3) write it to an xml file that would...
    3. permission to write a file (with java)
      hi there i've wrote a piece of java-code that runs great if i start it from eclipse. when i pack it to a jar-file and put it in the customtags...
    4. Unable To Open File "..." Because It Is Already Open With Write Permission
      I am trying to open a page for offline browsing and whenever I try to open a particular link I get this "Unable To Open File '...' Because It Is...
    5. log file sync vs. log file parallel write ?
      On 11 Dec 2002 14:48:41 -0800, bchorng@yahoo.com (Bass Chorng) wrote: The writes requested by a log file sync are evidently processed by...
  3. #2

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

    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! [url]www.microsoft.com/security[/url]
    (This posting is provided "AS IS", with no warranties, and confers no
    rights.)




    Steven Cheng[MSFT] Guest

  4. #3

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

    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]" <v-schang@online.microsoft.com> wrote in message
    news:%23Sp35mUyEHA.1884@cpmsftngxa10.phx.gbl...
    > 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! [url]www.microsoft.com/security[/url]
    > (This posting is provided "AS IS", with no warranties, and confers no
    > rights.)
    >
    >
    >
    >

    Umut Tezduyar Guest

  5. #4

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

    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
    [url]http://msdn.microsoft.com/library/en-us/cpgenref/html/gngrfCompilationSectio[/url]
    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! [url]www.microsoft.com/security[/url]
    (This posting is provided "AS IS", with no warranties, and confers no
    rights.)

    Steven Cheng[MSFT] Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139