[英]Request a key from web.config to a .cs file
場景:
我在appSettings的web.config中有一個鍵:
<add key="stylet" value="http://localhost/style.css"/>
我有一個.cs文件,包含以下代碼:
response.ContentType = "text/html";
response.Write("<html>");
response.Write("<head>");
response.Write(@"<title>See the page</title>");
response.Write(@"<link rel='stylesheet' type='text/css' />");
response.Write("</head>");
response.Write("<body>");
response.Write("<br /><table style='width: 500px'>");
response.Write("<tr><td class='ArticleIntro'>");
response.Write(propertyValue);
response.Write("</td></tr>");
response.Write("</table>");
response.Write("</body>");
response.Write("</html>");
問題:
如何在.cs文件中請求密鑰?
您可以為此使用ConfigurationManager類:
var value = ConfigurationManager.AppSettings["stylet"];
response.Write(@"<link href='"+ value +"' type='text/css' />");
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.