Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Web Development
  3. ASP.NET
  4. Access is denied. [modified]

Access is denied. [modified]

Scheduled Pinned Locked Moved ASP.NET
helpcsharphtmlasp-netdesign
30 Posts 5 Posters 4 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • I Im a beginner

    Hello all, I have an asp.net page uploading a file to D driver. It works well with ASP.NET server. protected void Button6_Click(object sender, EventArgs e) { FileUpload1.SaveAs("D:\\a.txt"); } when I published (to IIS) and ran it from IE, it caused an error: Access to the path 'D:\a.txt' is denied as following. [UnauthorizedAccessException: Access to the path 'D:\a.txt' is denied.] System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) +651 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) +1038 System.IO.FileStream..ctor(String path, FileMode mode) +64 System.Web.HttpPostedFile.SaveAs(String filename) +87 System.Web.UI.WebControls.FileUpload.SaveAs(String filename) +22 Examples.Button6_Click(Object sender, EventArgs e) +20 System.Web.UI.WebControls.Button.OnClick(EventArgs e) +105 System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +107 System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +7 System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +11 System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1746 Best regards, P/S: The code for this problem is here: I have an ASP.NET and this is the code in default.aspx:

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
    <title>Untitled Page</title>
    </head>
    <body>
    <form id="form1" runat="server">
    <asp:FileUpload ID="FileUpload1" runat="server" />
    <asp:Button ID="Button6" runat="server" önclick="Button6_Click" Text="Button" />
    <br />
    <br />
    </form>
    </body>
    </html>

    And here is the code into default.aspx.cs

    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button6\_Click(object sender, EventArgs e)
    {
        FileUpload1.SaveAs("D:\\\\a.txt");
    }
    

    After compiling the project, I published it as following: clicked right mouse on it and selected "Publish Website". Then I copy published files to a

    R Offline
    R Offline
    Raja Soosai
    wrote on last edited by
    #5

    Check Security permissions in d drive folders. Set every one to access permission Thanks, Raja

    I S 2 Replies Last reply
    0
    • C Christian Graus

      I'm a beginner wrote:

      Yes, D: Local Drive exists on my computer.

      Your computer is the server ?

      I'm a beginner wrote:

      I do not know how to check permissions both the root of D: Drive and IIS process, and I need your help.

      A website should not have permission to read or write above the application root, so even if you have a D drive on your server, I'd expect this not to work.

      Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.

      I Offline
      I Offline
      Im a beginner
      wrote on last edited by
      #6

      No, D: is my Local Drive and my computer is not a server. I have that project on my personal computer.

      <html xmlns="http://www.w3.org/1999/xhtml">
      <head runat="server">
      <title>Untitled Page</title>
      </head>
      <body>
      <form id="form1" runat="server">
      <asp:FileUpload ID="FileUpload1" runat="server" />
      <asp:Button ID="Button6" runat="server" onclick="Button6_Click" Text="Button" />
      <br />
      <br />
      </form>
      </body>
      </html>

      And then I have an event to fileUpload1 Control: protected void Button6_Click(object sender, EventArgs e) { FileUpload1.SaveAs("D:\\a.txt"); } I ran the project from virtual server of ASP.NET, it worked well. But when I published it to IIS server, it threw that error. Thanks,

      C 2 Replies Last reply
      0
      • R Raja Soosai

        Check Security permissions in d drive folders. Set every one to access permission Thanks, Raja

        I Offline
        I Offline
        Im a beginner
        wrote on last edited by
        #7

        My computer is not a server, but a desktop computer, so I can't

        rajaflowers wrote:

        Set every one to access permission

        Thanks,

        S C 2 Replies Last reply
        0
        • I Im a beginner

          No, D: is my Local Drive and my computer is not a server. I have that project on my personal computer.

          <html xmlns="http://www.w3.org/1999/xhtml">
          <head runat="server">
          <title>Untitled Page</title>
          </head>
          <body>
          <form id="form1" runat="server">
          <asp:FileUpload ID="FileUpload1" runat="server" />
          <asp:Button ID="Button6" runat="server" onclick="Button6_Click" Text="Button" />
          <br />
          <br />
          </form>
          </body>
          </html>

          And then I have an event to fileUpload1 Control: protected void Button6_Click(object sender, EventArgs e) { FileUpload1.SaveAs("D:\\a.txt"); } I ran the project from virtual server of ASP.NET, it worked well. But when I published it to IIS server, it threw that error. Thanks,

          C Offline
          C Offline
          Christian Graus
          wrote on last edited by
          #8

          I'm a beginner wrote:

          No, D: is my Local Drive and my computer is not a server. I have that project on my personal computer.

          So your computer IS where IIS is running, and therefore is the server, right ?

          I'm a beginner wrote:

          But when I published it to IIS server, it threw that error.

          Published it how ? Is IIS running on your local machine ?

          Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.

          S I 2 Replies Last reply
          0
          • C Christian Graus

            I'm a beginner wrote:

            No, D: is my Local Drive and my computer is not a server. I have that project on my personal computer.

            So your computer IS where IIS is running, and therefore is the server, right ?

            I'm a beginner wrote:

            But when I published it to IIS server, it threw that error.

            Published it how ? Is IIS running on your local machine ?

            Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.

            S Offline
            S Offline
            sashidhar
            wrote on last edited by
            #9

            He Still Did'nt get Your answer..! :laugh:

            LatestArticle :Log4Net Why Do Some People Forget To Mark as Answer .If It Helps.

            1 Reply Last reply
            0
            • I Im a beginner

              My computer is not a server, but a desktop computer, so I can't

              rajaflowers wrote:

              Set every one to access permission

              Thanks,

              S Offline
              S Offline
              sashidhar
              wrote on last edited by
              #10

              Have You seen CG answer..! show us the code ..! How did you save it..! May be group can help..!

              LatestArticle :Log4Net Why Do Some People Forget To Mark as Answer .If It Helps.

              modified on Tuesday, November 3, 2009 1:08 AM

              I 1 Reply Last reply
              0
              • R Raja Soosai

                Check Security permissions in d drive folders. Set every one to access permission Thanks, Raja

                S Offline
                S Offline
                sashidhar
                wrote on last edited by
                #11

                I dont think he has the permission.!

                LatestArticle :Log4Net Why Do Some People Forget To Mark as Answer .If It Helps.

                modified on Tuesday, November 3, 2009 1:09 AM

                I 1 Reply Last reply
                0
                • I Im a beginner

                  My computer is not a server, but a desktop computer, so I can't

                  rajaflowers wrote:

                  Set every one to access permission

                  Thanks,

                  C Offline
                  C Offline
                  Christian Graus
                  wrote on last edited by
                  #12

                  If you answered my questions, I'd understand what your situation is, and I'd be able to give you a definitive answer. Is IIS running on your desktop, or on a remote computer ? Where did you publish your site to ?

                  Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.

                  I 1 Reply Last reply
                  0
                  • I Im a beginner

                    No, D: is my Local Drive and my computer is not a server. I have that project on my personal computer.

                    <html xmlns="http://www.w3.org/1999/xhtml">
                    <head runat="server">
                    <title>Untitled Page</title>
                    </head>
                    <body>
                    <form id="form1" runat="server">
                    <asp:FileUpload ID="FileUpload1" runat="server" />
                    <asp:Button ID="Button6" runat="server" onclick="Button6_Click" Text="Button" />
                    <br />
                    <br />
                    </form>
                    </body>
                    </html>

                    And then I have an event to fileUpload1 Control: protected void Button6_Click(object sender, EventArgs e) { FileUpload1.SaveAs("D:\\a.txt"); } I ran the project from virtual server of ASP.NET, it worked well. But when I published it to IIS server, it threw that error. Thanks,

                    C Offline
                    C Offline
                    Christian Graus
                    wrote on last edited by
                    #13

                    Do you not want our help now ? If you'd just answer my question, I could help you

                    Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.

                    I 1 Reply Last reply
                    0
                    • C Christian Graus

                      I'm a beginner wrote:

                      No, D: is my Local Drive and my computer is not a server. I have that project on my personal computer.

                      So your computer IS where IIS is running, and therefore is the server, right ?

                      I'm a beginner wrote:

                      But when I published it to IIS server, it threw that error.

                      Published it how ? Is IIS running on your local machine ?

                      Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.

                      I Offline
                      I Offline
                      Im a beginner
                      wrote on last edited by
                      #14

                      Christian Graus wrote:

                      So your computer IS where IIS is running, and therefore is the server, right ?

                      Yes, I installed IIS into Windows XP on my personal computer.

                      Christian Graus wrote:

                      Published it how ? Is IIS running on your local machine ?

                      Yes, IIS is running on my local machine. After creating a ASP.NET project in Visual Studio 2008 and writing code as I mentioned above, then I compiled the project, clicked right mouse on it and selected "Publish Website". Then I copy published files to a folder example (a subfolder of C:\Inetpub\wwwroot). Finally, I ran IE and fill in the address: http://localhost/example/default.aspx, clicked button_6, and got the error. Thanks,

                      1 Reply Last reply
                      0
                      • C Christian Graus

                        Do you not want our help now ? If you'd just answer my question, I could help you

                        Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.

                        I Offline
                        I Offline
                        Im a beginner
                        wrote on last edited by
                        #15

                        I'm so sorry for replying late. I need your hands. Thanks,

                        1 Reply Last reply
                        0
                        • S sashidhar

                          Have You seen CG answer..! show us the code ..! How did you save it..! May be group can help..!

                          LatestArticle :Log4Net Why Do Some People Forget To Mark as Answer .If It Helps.

                          modified on Tuesday, November 3, 2009 1:08 AM

                          I Offline
                          I Offline
                          Im a beginner
                          wrote on last edited by
                          #16

                          The code for this problem is here: I have an ASP.NET and this is the code in default.aspx:

                          And here is the code into default.aspx.cs

                          protected void Page_Load(object sender, EventArgs e)
                          {

                          }
                          protected void Button6\_Click(object sender, EventArgs e)
                          {
                              FileUpload1.SaveAs("D:\\\\a.txt");
                          }
                          

                          After compiling the project, I published it as following:
                          clicked right mouse on it and selected "Publish Website". Then I copy published files to a folder example (a subfolder of C:\Inetpub\wwwroot). Finally, I ran IE and fill in the address: http://localhost/example/default.aspx, clicked button_6, and got the error.

                          I installed IIS on my local computer with version v5.1

                          Thanks,

                          S 1 Reply Last reply
                          0
                          • C Christian Graus

                            If you answered my questions, I'd understand what your situation is, and I'd be able to give you a definitive answer. Is IIS running on your desktop, or on a remote computer ? Where did you publish your site to ?

                            Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.

                            I Offline
                            I Offline
                            Im a beginner
                            wrote on last edited by
                            #17

                            I answered your questions above. Thanks,

                            1 Reply Last reply
                            0
                            • S sashidhar

                              I dont think he has the permission.!

                              LatestArticle :Log4Net Why Do Some People Forget To Mark as Answer .If It Helps.

                              modified on Tuesday, November 3, 2009 1:09 AM

                              I Offline
                              I Offline
                              Im a beginner
                              wrote on last edited by
                              #18

                              sashidhar wrote:

                              I dont think he has the permission.!

                              If I don't, why it can run correctly on Visual Studio 2008? Thanks,

                              C 1 Reply Last reply
                              0
                              • I Im a beginner

                                The code for this problem is here: I have an ASP.NET and this is the code in default.aspx:

                                And here is the code into default.aspx.cs

                                protected void Page_Load(object sender, EventArgs e)
                                {

                                }
                                protected void Button6\_Click(object sender, EventArgs e)
                                {
                                    FileUpload1.SaveAs("D:\\\\a.txt");
                                }
                                

                                After compiling the project, I published it as following:
                                clicked right mouse on it and selected "Publish Website". Then I copy published files to a folder example (a subfolder of C:\Inetpub\wwwroot). Finally, I ran IE and fill in the address: http://localhost/example/default.aspx, clicked button_6, and got the error.

                                I installed IIS on my local computer with version v5.1

                                Thanks,

                                S Offline
                                S Offline
                                sashidhar
                                wrote on last edited by
                                #19

                                I'm a beginner wrote:

                                s("D:\\a.txt");

                                whts this..! I used like this it worked..!

                                FileUpload1.SaveAs(@"C:\temp\" + FileUpload1.FileName);

                                LatestArticle :Log4Net Why Do Some People Forget To Mark as Answer .If It Helps.

                                1 Reply Last reply
                                0
                                • I Im a beginner

                                  sashidhar wrote:

                                  I dont think he has the permission.!

                                  If I don't, why it can run correctly on Visual Studio 2008? Thanks,

                                  C Offline
                                  C Offline
                                  Christian Graus
                                  wrote on last edited by
                                  #20

                                  I believe that the web server that's built in to visual studio doesn't enforce the sort of security that IIS does, simply because no-one is going to run a live website with it. Imagine if my site is on a web host that runs a lot of other sites. They are probably all going to be folders under the IIS root. So, if I were to write code that looks for files with a path starting in a .., I could try to read files that belong to another site. That's just one reason why IIS doesn't let you read or write above the root of the web application.

                                  Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.

                                  I 1 Reply Last reply
                                  0
                                  • C Christian Graus

                                    I believe that the web server that's built in to visual studio doesn't enforce the sort of security that IIS does, simply because no-one is going to run a live website with it. Imagine if my site is on a web host that runs a lot of other sites. They are probably all going to be folders under the IIS root. So, if I were to write code that looks for files with a path starting in a .., I could try to read files that belong to another site. That's just one reason why IIS doesn't let you read or write above the root of the web application.

                                    Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.

                                    I Offline
                                    I Offline
                                    Im a beginner
                                    wrote on last edited by
                                    #21

                                    Your answer is absolutely right. If I save the file to one of the folders under the project, it works with IIS. So I wonder if there is any way to write directly to another location like I did (Configure IIS for example) because when I searched information, some people say that there is a way by adding this line in web.config file between tag <system.web> and </system.web>:

                                    <identity impersonate="true"/>

                                    I tried, but it did not work. Thanks for your help,

                                    S 1 Reply Last reply
                                    0
                                    • I Im a beginner

                                      Your answer is absolutely right. If I save the file to one of the folders under the project, it works with IIS. So I wonder if there is any way to write directly to another location like I did (Configure IIS for example) because when I searched information, some people say that there is a way by adding this line in web.config file between tag <system.web> and </system.web>:

                                      <identity impersonate="true"/>

                                      I tried, but it did not work. Thanks for your help,

                                      S Offline
                                      S Offline
                                      sashidhar
                                      wrote on last edited by
                                      #22

                                      What abt this code..!

                                      protected void Page_Load(object sender, EventArgs e)
                                      {

                                      }
                                      protected void Button6\_Click(object sender, EventArgs e)
                                      {
                                          FileUpload1.SaveAs("D:\\\\a.txt");  <----
                                      }
                                      

                                      use the following code..!

                                      //Make sure a folder exixt folder
                                      FileUpload1.SaveAs(@"D:\SomeFolderName\" + FileUpload1.FileName);

                                      Your wasting the time..!:cool:

                                      LatestArticle :Log4Net Why Do Some People Forget To Mark as Answer .If It Helps.

                                      I 1 Reply Last reply
                                      0
                                      • S sashidhar

                                        What abt this code..!

                                        protected void Page_Load(object sender, EventArgs e)
                                        {

                                        }
                                        protected void Button6\_Click(object sender, EventArgs e)
                                        {
                                            FileUpload1.SaveAs("D:\\\\a.txt");  <----
                                        }
                                        

                                        use the following code..!

                                        //Make sure a folder exixt folder
                                        FileUpload1.SaveAs(@"D:\SomeFolderName\" + FileUpload1.FileName);

                                        Your wasting the time..!:cool:

                                        LatestArticle :Log4Net Why Do Some People Forget To Mark as Answer .If It Helps.

                                        I Offline
                                        I Offline
                                        Im a beginner
                                        wrote on last edited by
                                        #23

                                        That code placed in default.aspx.cs file is used to save a file whose path is got from FileUpload1 Control to D:\a.txt (Actually, it saves and change the original file's name into a.txt). If I modify it as following, it works:

                                        protected void Button6_Click(object sender, EventArgs e)
                                        {
                                        FileUpload1.SaveAs(Server.Map("~")+@"\a.txt"); <----
                                        }

                                        But I do want it to do directly on D: Drive (or another Drive, not C: Drive) Thanks,

                                        S 1 Reply Last reply
                                        0
                                        • I Im a beginner

                                          That code placed in default.aspx.cs file is used to save a file whose path is got from FileUpload1 Control to D:\a.txt (Actually, it saves and change the original file's name into a.txt). If I modify it as following, it works:

                                          protected void Button6_Click(object sender, EventArgs e)
                                          {
                                          FileUpload1.SaveAs(Server.Map("~")+@"\a.txt"); <----
                                          }

                                          But I do want it to do directly on D: Drive (or another Drive, not C: Drive) Thanks,

                                          S Offline
                                          S Offline
                                          sashidhar
                                          wrote on last edited by
                                          #24

                                          Have You tried the above code..! Make sure a folder is created..!

                                          LatestArticle :Log4Net Why Do Some People Forget To Mark as Answer .If It Helps.

                                          I 1 Reply Last reply
                                          0
                                          Reply
                                          • Reply as topic
                                          Log in to reply
                                          • Oldest to Newest
                                          • Newest to Oldest
                                          • Most Votes


                                          • Login

                                          • Don't have an account? Register

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • World
                                          • Users
                                          • Groups