472,799 Members | 1,642 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,799 software developers and data experts.

Security problem when dynamically creating directories

I am trying to dynamically create directories in my ASP.NET application (I
am using Server.MapPath("/")+"test" as the folder)
and I am getting a DirectoryNotFoundException saying "Could not find a part
of the path "D:\".
My site is hosted on a public ISP that for obvious security reasons does not
allow my read access above my wwwroot folder which seems to be a problem
when trying to create directories...

Is there any way to solve this?

--
Eran Kampf
blog: http://www.ekampf.com/blog
Sharp3D.Math: http://www.ekampf.com/Sharp3D.Math/
Nov 16 '05 #1
6 3606
Certain ISPs won't let you touch the filesystem even in the wwwroot. Your
only option is to pretty much stick with the ISPs rules, be a good boy and
create your directories only within wwwroot.

Actually create them in a subdirectory within wwwroot, so that you can limit
write access control to only that subdir (and no code lives there).

- Sahil Malik
You can reach me thru my blog at
http://www.dotnetjunkies.com/weblog/sahilmalik

"Eran Kampf" <er**@ekampf.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
I am trying to dynamically create directories in my ASP.NET application (I
am using Server.MapPath("/")+"test" as the folder)
and I am getting a DirectoryNotFoundException saying "Could not find a part of the path "D:\".
My site is hosted on a public ISP that for obvious security reasons does not allow my read access above my wwwroot folder which seems to be a problem
when trying to create directories...

Is there any way to solve this?

--
Eran Kampf
blog: http://www.ekampf.com/blog
Sharp3D.Math: http://www.ekampf.com/Sharp3D.Math/

Nov 16 '05 #2
The following error is when trying to create a subdirectory udner wwwroot
which is fine with the ISP....
It seems that the problem occurs because of ISP security above the wwwroot
level.

By the way,
The ISP support guy tried creating a directory using old asp (FileSystem
object) and had no problems...

"Sahil Malik" <co*****************@nospam.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
Certain ISPs won't let you touch the filesystem even in the wwwroot. Your
only option is to pretty much stick with the ISPs rules, be a good boy and
create your directories only within wwwroot.

Actually create them in a subdirectory within wwwroot, so that you can
limit
write access control to only that subdir (and no code lives there).

- Sahil Malik
You can reach me thru my blog at
http://www.dotnetjunkies.com/weblog/sahilmalik

"Eran Kampf" <er**@ekampf.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
I am trying to dynamically create directories in my ASP.NET application
(I
am using Server.MapPath("/")+"test" as the folder)
and I am getting a DirectoryNotFoundException saying "Could not find a

part
of the path "D:\".
My site is hosted on a public ISP that for obvious security reasons does

not
allow my read access above my wwwroot folder which seems to be a problem
when trying to create directories...

Is there any way to solve this?

--
Eran Kampf
blog: http://www.ekampf.com/blog
Sharp3D.Math: http://www.ekampf.com/Sharp3D.Math/


Nov 16 '05 #3
YK
Hi Eran,

If you are sure that you can write to wwwroot using the old ASP approach
(possibly through FileSystemObject), you can try enable impersonation for
your ASP.NET application. In fact, the default ASPNET account needs to
impersonate the client (or another account with higher access privilege on
wwwroot) in order for the file system to honour the NTFS permission.

Thanks,
YK


"Eran Kampf" wrote:
The following error is when trying to create a subdirectory udner wwwroot
which is fine with the ISP....
It seems that the problem occurs because of ISP security above the wwwroot
level.

By the way,
The ISP support guy tried creating a directory using old asp (FileSystem
object) and had no problems...

"Sahil Malik" <co*****************@nospam.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
Certain ISPs won't let you touch the filesystem even in the wwwroot. Your
only option is to pretty much stick with the ISPs rules, be a good boy and
create your directories only within wwwroot.

Actually create them in a subdirectory within wwwroot, so that you can
limit
write access control to only that subdir (and no code lives there).

- Sahil Malik
You can reach me thru my blog at
http://www.dotnetjunkies.com/weblog/sahilmalik

"Eran Kampf" <er**@ekampf.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
I am trying to dynamically create directories in my ASP.NET application
(I
am using Server.MapPath("/")+"test" as the folder)
and I am getting a DirectoryNotFoundException saying "Could not find a

part
of the path "D:\".
My site is hosted on a public ISP that for obvious security reasons does

not
allow my read access above my wwwroot folder which seems to be a problem
when trying to create directories...

Is there any way to solve this?

--
Eran Kampf
blog: http://www.ekampf.com/blog
Sharp3D.Math: http://www.ekampf.com/Sharp3D.Math/



Nov 16 '05 #4
Eran,

Server.MapPath("/") will return the path to the site root, which is not
necessarily the root folder of your application. You should have better
luck with Server.MapPath(null). In addition, the value returned may not
have a trailing backslash. To ensure proper path generation, use
Path.Combine rather than simple concatenation. e.g.:
System.IO.Path.Combine(Server.MapPath(null), "test").

If the above still doesn't work, have you tried simply writing the output
from Server.MapPath to an ASPX page so that you can view the value? Is the
returned value a path on which the execution context user should have
adequate permissions to perform the operations that you are attempting?

HTH,
Nicole

"Eran Kampf" <er**@ekampf.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
I am trying to dynamically create directories in my ASP.NET application (I
am using Server.MapPath("/")+"test" as the folder)
and I am getting a DirectoryNotFoundException saying "Could not find a
part
of the path "D:\".
My site is hosted on a public ISP that for obvious security reasons does
not
allow my read access above my wwwroot folder which seems to be a problem
when trying to create directories...

Is there any way to solve this?

--
Eran Kampf
blog: http://www.ekampf.com/blog
Sharp3D.Math: http://www.ekampf.com/Sharp3D.Math/

Nov 16 '05 #5
The path I am trying to create is correct.
I checked the knowledge base and I think the problem is due to the fact that
D is a mapped network drive while the asp.net worker process is a local user
that has no network access and thus cannot access the network drive.

If that is true then
1. How creating a directory with old ASP FileSystem object works fine?
2. How come creating\reading\writing files in existing directories work
fine?

"Nicole Calinoiu" <calinoiu REMOVETHIS AT gmail DOT com> wrote in message
news:On**************@tk2msftngp13.phx.gbl...
Eran,

Server.MapPath("/") will return the path to the site root, which is not
necessarily the root folder of your application. You should have better
luck with Server.MapPath(null). In addition, the value returned may not
have a trailing backslash. To ensure proper path generation, use
Path.Combine rather than simple concatenation. e.g.:
System.IO.Path.Combine(Server.MapPath(null), "test").

If the above still doesn't work, have you tried simply writing the output
from Server.MapPath to an ASPX page so that you can view the value? Is
the returned value a path on which the execution context user should have
adequate permissions to perform the operations that you are attempting?

HTH,
Nicole

"Eran Kampf" <er**@ekampf.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
I am trying to dynamically create directories in my ASP.NET application (I
am using Server.MapPath("/")+"test" as the folder)
and I am getting a DirectoryNotFoundException saying "Could not find a
part
of the path "D:\".
My site is hosted on a public ISP that for obvious security reasons does
not
allow my read access above my wwwroot folder which seems to be a problem
when trying to create directories...

Is there any way to solve this?

--
Eran Kampf
blog: http://www.ekampf.com/blog
Sharp3D.Math: http://www.ekampf.com/Sharp3D.Math/


Nov 16 '05 #6
"Eran Kampf" <er**@ekampf.com> wrote in message
news:Oe**************@TK2MSFTNGP11.phx.gbl...
The path I am trying to create is correct.
I checked the knowledge base and I think the problem is due to the fact
that D is a mapped network drive while the asp.net worker process is a
local user that has no network access and thus cannot access the network
drive.
If it's a mapped network drive, and you're trying to create directories
within you application folder, is your application folder running from this
mapped drive? If not, could you please provide the directory mapping for
your application and the target folders?

If that is true then
1. How creating a directory with old ASP FileSystem object works fine?
For starters, it's most likely using a different user context.

2. How come creating\reading\writing files in existing directories work
fine?
Without more information, all I could possibly do is make some rather wild
guesses. <g> It would really help if you could provide a relevant code
extract, indicating the line on which the exception is thrown and the
complete exception details.


"Nicole Calinoiu" <calinoiu REMOVETHIS AT gmail DOT com> wrote in message
news:On**************@tk2msftngp13.phx.gbl...
Eran,

Server.MapPath("/") will return the path to the site root, which is not
necessarily the root folder of your application. You should have better
luck with Server.MapPath(null). In addition, the value returned may not
have a trailing backslash. To ensure proper path generation, use
Path.Combine rather than simple concatenation. e.g.:
System.IO.Path.Combine(Server.MapPath(null), "test").

If the above still doesn't work, have you tried simply writing the output
from Server.MapPath to an ASPX page so that you can view the value? Is
the returned value a path on which the execution context user should have
adequate permissions to perform the operations that you are attempting?

HTH,
Nicole

"Eran Kampf" <er**@ekampf.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
I am trying to dynamically create directories in my ASP.NET application
(I
am using Server.MapPath("/")+"test" as the folder)
and I am getting a DirectoryNotFoundException saying "Could not find a
part
of the path "D:\".
My site is hosted on a public ISP that for obvious security reasons does
not
allow my read access above my wwwroot folder which seems to be a problem
when trying to create directories...

Is there any way to solve this?

--
Eran Kampf
blog: http://www.ekampf.com/blog
Sharp3D.Math: http://www.ekampf.com/Sharp3D.Math/



Nov 16 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Billy Cormic | last post by:
Hello, I am interested in dynamically creating temp tables using a variable in MS SQL Server 2000. For example: DECLARE @l_personsUID int select @l_personsUID = 9842
3
by: dave | last post by:
I am using vs.net 2003 on windows xp. After clicking on a project within my solution and selecting create new folder vs.net responds back with , the "directory already exists". If i look at the...
2
by: Patrick | last post by:
I want to define a set of web-form templates in XML and render the equivalent web-form with ASP.NET, then process any input server controls on the form. Reading the XML file from Page_load is...
1
by: andrew | last post by:
So I spent ages trying to work out what the problem was with my code when I did this and found a post which led me to the very simple solution. I use WebMatrix so I'm not sure if this is a major...
2
by: epigram | last post by:
I'm dynamically creating a number of radio buttons on my aspx page based upon data read from a db. Each radio button has autopostback turned on. I'm experiencing two problems. 1) I am reading...
1
by: jonpfl | last post by:
All, I am new to javascript and I am having problems dynamically creating rows and setting attributes. The following works on IE7.x but not IE6.x. Is there another way of creating a checkbox...
8
by: BillE | last post by:
When I create a control dynamically and it grows according to the content, the control Height property still returns the original default control height instead of the height after expanding. ...
4
by: Lewis Holmes | last post by:
Hi I have the following situation in one of my asp.net pages. The user can add multiple table rows to a form by selecting a button. These rows can contain asp.net controls. When this button is...
0
by: david wright | last post by:
--- On Fri, 9/5/08, srinivasan srinivas <sri_annauni@yahoo.co.inwrote: this appears to be working, what where you expecting? "An upper case "S" means there is no executable permission, but...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: lllomh | last post by:
How does React native implement an English player?
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.