Can I use Server.MapPath in web.config?

  • Thread starter Thread starter Rich
  • Start date Start date
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
 
I would say, split up your connection string into 2 parts, and cal
Server.MapPath on the apropriate part.
 
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.
 
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 :).
 
Back
Top