Sandy Sandy - 1 year ago 192
ASP.NET (C#) Question

How to access web.config settings directly in .aspx page?

I've created a web page and it contains some settings value in web.cofig for example images.So i want to give the path of images in Web.Config file and file name in that particular image src.

I wanted to read that settings only in aspx page not in codebehind.

For example

Below is my code:

<add key="ImagePath" value=""/>

and in my aspx page,

img id="ImgHeader" runat="server" src="<%ConfigurationManager.AppSettings["ImagePath"]%>" />

Answer Source
<img id="ImgHeader" runat="server" src="<%$ ConfigurationSettings.AppSettings["ImagePath"] %>" />

Should do the trick.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download