-
Apr 19th, 2013, 01:56 PM
#1
Thread Starter
Frenzied Member
[RESOLVED] Access Denied on File Delete
I have an application that allows users to use a FileUpload object to upload files to a directory on the web server. The upload part works fine, but if they later try to delete the file they get an error that Access to the path is denied. The Application Pool for the site runs under NetworkService, and on the folder they are loading and trying to delete these files from I give NetworkService Full control. Anyt thoughts as to what else I may need to do?
Sean
Some days when I think about the next 30 years or so of my life I am going to spend writing code, I happily contemplate stepping off a curb in front of a fast moving bus.
-
Apr 19th, 2013, 06:31 PM
#2
Re: Access Denied on File Delete
Yeah, just give the "users" account read,write,modify. Should work.
ἄνδρα μοι ἔννεπε, μοῦσα, πολύτροπον, ὃς μάλα πολλὰ
πλάγχθη, ἐπεὶ Τροίης ἱερὸν πτολίεθρον ἔπερσεν·
-
Apr 25th, 2013, 02:26 PM
#3
Thread Starter
Frenzied Member
Re: Access Denied on File Delete
Originally Posted by sapator
Yeah, just give the "users" account read,write,modify. Should work.
It already has full control. Something weird is going on, and I'm not sure what. I'm wondering if it has something to do with the folder it is in. I didn't really know IIS 7 when I loaded this guy (can't say I know it much better now, so I just dropped the website where the default page was setup already which was a weird place under inetpub (htdocs folder).
Sean
Some days when I think about the next 30 years or so of my life I am going to spend writing code, I happily contemplate stepping off a curb in front of a fast moving bus.
-
Apr 25th, 2013, 09:05 PM
#4
Re: Access Denied on File Delete
Create you website, after that create a new folder where the to del - files will be in, now insert an new aspx page inside the file delete folder, a blank default.aspx will do.Give the appropriate permissions. Let me know.
If it does not work then it's your code. Just to be on the safe side, write here the exact permissions you give to this folder and the exact code you are using for deleting the files.
ἄνδρα μοι ἔννεπε, μοῦσα, πολύτροπον, ὃς μάλα πολλὰ
πλάγχθη, ἐπεὶ Τροίης ἱερὸν πτολίεθρον ἔπερσεν·
-
Apr 26th, 2013, 01:26 PM
#5
Thread Starter
Frenzied Member
Re: Access Denied on File Delete
Code:
Protected Sub gvFiles_RowCommand(sender As Object, e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles gvFiles.RowCommand
' Finish Me
' Restrict users to Stephen/Martin
If e.CommandName = "Delete" Then
Dim oSQL As New clsSQL
Dim strFileName As String = ""
oSQL.GetFileName(strFileName, gvFiles.DataKeys(e.CommandArgument).Value())
Dim strFilePath As String = Server.MapPath("~\ACSDocs\" & strFileName)
System.IO.File.Delete(strFilePath)
oSQL.DeleteACSDocs(gvFiles.DataKeys(e.CommandArgument).Value())
oSQL.LoadACSDocs()
gvFiles.DataSource = oSQL.Dataset.Tables("ACSDocs")
gvFiles.DataBind()
End If
End Sub
Permission wise I am giving Network Service (app pool runs under) Full Control. I've tried Users, Administrators, System. Changed the App Pool to the IIS User Account and gave it full control. It's bizarre. Before we moved to a VPS and were on a shared server they could delete, so I don't think it is a code issue.
Sean
Some days when I think about the next 30 years or so of my life I am going to spend writing code, I happily contemplate stepping off a curb in front of a fast moving bus.
-
Apr 26th, 2013, 05:49 PM
#6
Re: Access Denied on File Delete
Can you try deleting outside a gridview? I am not sure how well the server is behaving with in grid delete.
Also try changing to this: Server.MapPath("\\ACSDocs\ ..... etc)
ἄνδρα μοι ἔννεπε, μοῦσα, πολύτροπον, ὃς μάλα πολλὰ
πλάγχθη, ἐπεὶ Τροίης ἱερὸν πτολίεθρον ἔπερσεν·
-
May 9th, 2013, 09:00 AM
#7
Thread Starter
Frenzied Member
Re: Access Denied on File Delete
Originally Posted by sapator
Can you try deleting outside a gridview? I am not sure how well the server is behaving with in grid delete.
Also try changing to this: Server.MapPath("\\ACSDocs\ ..... etc)
Strangely this may be my issue and I don't know why.
I tried moving where the documents are to just C:\Documents\ACSDocs\ on the server, gave it rights to Network Service, dropped a button on it and a text dox and have one line:
Code:
System.IO.File.Delete(txtTestDelete.Text)
Deletes the file no problem. So I thought I had a fix, changed the code to point to that directory:
Code:
If e.CommandName = "Delete" Then
Dim oSQL As New clsSQL
Dim strFileName As String = ""
oSQL.GetFileName(strFileName, gvFiles.DataKeys(e.CommandArgument).Value())
'Dim strFilePath As String = Server.MapPath("~\ACSDocs\" & strFileName)
Dim strFilePath As String = "C:\Documents\ACSDocs\" & strFileName
System.IO.File.Delete(strFilePath)
oSQL.DeleteACSDocs(gvFiles.DataKeys(e.CommandArgument).Value())
oSQL.LoadACSDocs()
gvFiles.DataSource = oSQL.Dataset.Tables("ACSDocs")
gvFiles.DataBind()
End If
Run the application again, get the same Access Denied error. Both my Test.aspx page and my real .aspx page live in the same directory. I'm a bit at a loss. You think the GridView somehow is screwing it up?
Sean
Some days when I think about the next 30 years or so of my life I am going to spend writing code, I happily contemplate stepping off a curb in front of a fast moving bus.
-
May 9th, 2013, 09:50 AM
#8
Thread Starter
Frenzied Member
Re: Access Denied on File Delete
Huh almost sure it is the gridview now. Thought maybe it was the built in delete, so did a button instead and named the command "deletefile" but that didn't resolve it. So I tried dropping the one liner from my test page that worked on the page outside the gridview and sure enough it can delete from the directory no problem.
So...any advice on what in the RowCommand would cause it I am open to.
Sean
Some days when I think about the next 30 years or so of my life I am going to spend writing code, I happily contemplate stepping off a curb in front of a fast moving bus.
-
May 9th, 2013, 11:08 AM
#9
Thread Starter
Frenzied Member
Re: Access Denied on File Delete
SOB ok I figured it out. I feel pretty stupid now.
This issue is with this line:
Code:
oSQL.GetFileName(strFileName, gvFiles.DataKeys(e.CommandArgument).Value())
returning an empty string, so instead of trying to delete a file, I was trying to delete a directory and that was failing.
Thanks for the help.
Sean
Some days when I think about the next 30 years or so of my life I am going to spend writing code, I happily contemplate stepping off a curb in front of a fast moving bus.
-
May 31st, 2024, 10:59 AM
#10
New Member
Re: Access Denied on File Delete
Originally Posted by SeanGrebey
SOB ok I figured it out. I feel pretty stupid now.
This issue is with this line:
Code:
oSQL.GetFileName(strFileName, gvFiles.DataKeys(e.CommandArgument).Value())
returning an empty string, so instead of trying to delete a file, I was trying to delete a directory and that was failing.
Thanks for the help.
Have you tried Longpath tool?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|