Can I use Server.MapPath in web.config?

R

Rich

The following appsetting in web.config works fine if
hardcoded path (dir1 is virtual dir).

<appSettings>
<add key="conn"
value="PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA Source=d:\dir1
\db\northwind.mdb"/>
</appSettings>

But I would like to make the path dynamic with
Server.MapPath except I don't know how to apply it in
web.config. Is Server.MapPath even supported in
web.config?

<appSettings>
<add key="conn"
value="PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA Source=" +
Server.MapPath + "\db\northwind.mdb"/>
</appSettings>

Any suggestions for the correct syntax would be greatly
appreciated.

Thanks,
Rich
 
M

Marina

I would say, split up your connection string into 2 parts, and cal
Server.MapPath on the apropriate part.
 
K

Kevin Spencer

But I would like to make the path dynamic with
Server.MapPath except I don't know how to apply it in
web.config. Is Server.MapPath even supported in
web.config?

No. If you need to execute code, you need to do it in a class, such as your
global class defined in the global.asax file.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.
 
R

Rich

Thanks. I didn't think web.config supported stuff like
that. As for adding code to global.asax, I could just add
code to a server script tag in the aspx page which is what
I was originally doing and looks like I will have to keep
doing :).
 

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

Top