?
Solved

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

Posted on 2003-02-25
13
Medium Priority
?
345 Views
Last Modified: 2008-02-01
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
Comment
Question by:johnwood
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 4
  • 2
  • +1
13 Comments
 
LVL 7

Expert Comment

by:markhoy
ID: 8016577
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
 

Author Comment

by:johnwood
ID: 8016659
Hi markhoy,

What code you want me to post? I have posted that....
myString = Server.MapPath("..\Db\myData.mdb")
0
 
LVL 7

Expert Comment

by:markhoy
ID: 8016836
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
Industry Leaders: 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!

 

Author Comment

by:johnwood
ID: 8017250
Hi markhoy,
the link you show me doesn't say anything about ".."!
0
 
LVL 1

Expert Comment

by:hbaber
ID: 8017386
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
 
LVL 7

Expert Comment

by:markhoy
ID: 8017398
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
 

Author Comment

by:johnwood
ID: 8017919
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
 
LVL 7

Accepted Solution

by:
markhoy earned 300 total points
ID: 8018011
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
 

Author Comment

by:johnwood
ID: 8018294
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
 

Expert Comment

by:Ivanna1997
ID: 8019706
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
 

Author Comment

by:johnwood
ID: 8020131
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
 

Author Comment

by:johnwood
ID: 8020869
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
 
LVL 1

Expert Comment

by:hbaber
ID: 8026364
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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question