Problem with MapPath and inheritance

D

David Berman

Hello,
I'm having a problem using MapPath. The problem is that my
production site is www.mydomain.com, but my development site is
www.devdomain.com/myproject. In the root folder I have a base class
page, in a folder called /learn I have a page that uses my base class.
The baseclass opens a file and writes the output to the browser. It
finds the file using MapPath("/templates/header.htm"). This works fine
on the production server, however it doesn't work on the development
machine because the initial / gets interpreted as "start from the root".
If I don't put the first /, then it doesn't work either because the base
class calls mappath which maps to "/learn/templates/header.htm" which
isn't where the file is.
How can I manage this so that it works using relative paths, so I can
develop on my development machine and then publish to my production
machine?

Thank you!

David




Meet people for friendship, contacts,
or romance using free instant messaging software! See a picture you
like? Click once for a private conversation with that person!

www.SocialNetwork.com - Get free software!
 
C

Craig Deelsnyder

David said:
Hello,
I'm having a problem using MapPath. The problem is that my
production site is www.mydomain.com, but my development site is
www.devdomain.com/myproject. In the root folder I have a base class
page, in a folder called /learn I have a page that uses my base class.
The baseclass opens a file and writes the output to the browser. It
finds the file using MapPath("/templates/header.htm"). This works fine
on the production server, however it doesn't work on the development
machine because the initial / gets interpreted as "start from the root".
If I don't put the first /, then it doesn't work either because the base
class calls mappath which maps to "/learn/templates/header.htm" which
isn't where the file is.
How can I manage this so that it works using relative paths, so I can
develop on my development machine and then publish to my production
machine?

You can use the ~ notation which means 'the root folder of my app'.

so ~/folder/file.aspx

would go into your app's root directory, into the folder folder...

You might be able to do this in your MapPath directly...if not, Control
has a method called ResolveUrl which will map a ~ url to its virtual path

MapPath("~/templates/header.htm") //might work
or
MapPath(this.Page.ResolveUrl("~/templates/header.htm"))

the latter one, I assume we're inside a user control...you need a
Control to get access to that method....
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top