How to access web.config settings directly in .asp

2020-02-23 06:19发布

I've created a web page and it contains some settings value in Web.Config 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:

Web.Config:
<add key="ImagePath" value="http://192.168.0.181/Labeling/Images/"/>

and in my aspx page,

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

4条回答
成全新的幸福
2楼-- · 2020-02-23 06:38
<img id="ImgHeader" runat="server" src="<%$ ConfigurationSettings.AppSettings["ImagePath"] %>" />

Should do the trick.

查看更多
Viruses.
3楼-- · 2020-02-23 06:38

Waqas Iqbal's answer:

<%$ AppSettings:ImagePath %> 

from Binding ASP.Net Web.Config Settings To .ASPX File <a href></a>? worked nicely!

查看更多
Melony?
4楼-- · 2020-02-23 06:54
<%= ConfigurationSettings.AppSettings["ImagePath"] %>
查看更多
狗以群分
5楼-- · 2020-02-23 06:54

This worked for me:

<%= ConfigurationManager.AppSettings("ImagePath") %>
查看更多
登录 后发表回答