• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 354
  • Last Modified:

Can not use server.MapPath("..")?

Hi Experts,

I have used MapPath a lot, such as
server.MapPath("..\Db\myData.mdb")
and have never got problem. Today, I found a website which said:
The MapPath method does not support relative path syntax (.) or (..). For example, the following relative path, ../MyDir/MyFile.txt, returns an error.

Can you check that at
http://www.fuzzysoftware.com/tagreference.asp?objectid=5&tagid=39
and tell me what you think?
0
johnwood
Asked:
johnwood
  • 6
  • 4
  • 2
  • +1
1 Solution
 
markhoyCommented:
is it the serverMapPath or are you using an INCLUDE VIRTUAL ="../name.inc"? as well and it's falling over there? can you post the code?
0
 
johnwoodAuthor Commented:
Hi markhoy,

What code you want me to post? I have posted that....
myString = Server.MapPath("..\Db\myData.mdb")
0
 
markhoyCommented:
sorry! misread your question. Just because it is written on one website doesn't make it correct. YEs, you CAN use MapPath using a relative path- in fact that is the point- the path is always relative to a file path!

see: http://www.learnasp.com/learn/pathmap.asp

never heard of the fuzzylogic site and I use other ones myself. I suggest you do the same.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
johnwoodAuthor Commented:
Hi markhoy,
the link you show me doesn't say anything about ".."!
0
 
hbaberCommented:
Several options exist.  IIS4 had parent paths turned off by default (which will allow "..") and IIS5 has it turned on (will not allow "..").  If you uncheck "Enable parent paths" you can use .. again.  What I would suggest is putting your connectionstring in the global.asa then in your code using the application("whatever").  This makes it much easier to change you connections later and get you away from ".."

Save this text as global.asa in your root folder of you r web app.
<SCRIPT LANGUAGE=VBScript RUNAT=Server>
Sub Application_OnStart
          Application("whatever") = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=d:\inetpub\wwwroot\database\contacts.mdb"
End Sub
</SCRIPT>

in your ASP change your connection to
Conn.Open Application("whatever")


Hope that helps.

0
 
markhoyCommented:
have you tried it? I use this on several working sites:

dim DBPath, strConnect

DBPath=server.mapPath("..\messages\wche.mdb")


strConnect = "Driver={Microsoft Access Driver (*.mdb)};DBQ=" & DBPath & ";"


(although I tend to use OLE for the driver).

0
 
johnwoodAuthor Commented:
Hi Experts,

My problem looks not so easy to be solved.

I use
myString = Server.MapPath("..\Db\myData.mdb")
in a server (not mine) in a .asp file without anyproblem. Now, I am trying to do the same thing in a .aspx file in the same server and the same folder but got error! I then asked the help person of the server and he pointed me to the link
http://www.fuzzysoftware.com/tagreference.asp?objectid=5&tagid=39
which said
The MapPath method does not support relative path syntax (.) or (..). For example, the following relative path, ../MyDir/MyFile.txt, returns an error.

Now, only way is to use the full path starts from d:\....?
0
 
markhoyCommented:
Well, 50/50. ServerMapPath DOES support relative paths but if server config disallows it you can't use it (but why would anyone want to?!). Looks like you'll have to  use a fixed path (you can use a server variable as well)  :-)

or does it support .MapPath("\ado\myData.mdb") ( to go from the root of your folder)?
0
 
johnwoodAuthor Commented:
To markhoy:

>if server config disallows it
How can disallow .aspx files but not .asp files?

>or does it support .MapPath("\ado\myData.mdb")
No!
We need to put all .html, .asp files in d://theRoot/a sub-Root/ and when doing http://www.myDomain/, the index.sap page opened. If we do .MapPath("\") from a file in
d://theRoot/a sub-Root/
it will return
d://theRoot/a sub-Root/
not
d://theRoot/
0
 
Ivanna1997Commented:
Hi All,

ASPX needs a .net server
If the server you try to use isn't a .NET server you run into this type of errors

0
 
johnwoodAuthor Commented:
To Ivanna1997:

The server supports ASP and ASP.Net. That is at least what the server company said and I can run some other simple ASP.Net script.
0
 
johnwoodAuthor Commented:
Hi All,

The person from my hosting has just answered me:
"as from Microsoft suggestion ../.. (parent path) option has been disable from ASP.NET due to a security issue."

Do you believe???!!!
0
 
hbaberCommented:
yes.  This is what I explained in my original message.  IIS 5 has "Enable parent paths" turned on by default and IIS 4 didn't.  Since this a security issue and is on an ISP server getting them to change it is not likely.  You have to recode your pages.

0

Featured Post

[Webinar] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

  • 6
  • 4
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now