【问题标题】:read appsetting from web.config on form action在表单操作中从 web.config 读取 appsetting
【发布时间】:2014-02-12 01:32:44
【问题描述】:

我想从我的 aspx 页面上的 web.config 文件中读取 appsetting 但这不是我尝试的成功。我在这里做错了什么

以下是我的 web.config 设置

 <appSettings>  
    <add key="SECURE_URL" value="https://wwww.astrick.com"/>
  </appSettings>

下面是aspx页面部分,想看这个

<form action="<%=System.Configuration.ConfigurationManager.AppSettings("SECURE_URL")%>/park/notice/payment.asp"
                            method="post">
  <div>
     <ul>
       <li><strong>Search By Parking Violation Number</strong>
         <ul>
           <li>
              <div style="width: 200px; float: left;">
                      Parking Violation Number</div>
                   <div style="width: 200px; float: left;">
                     <input type="text" class="input1" name="Parking_Ticket_Number" size="15" maxlength="255" /></div>
                  <div style="width: 150px; float: left;">
                     <input type="submit" class="submit1" value="Search " /></div>
                          <br style="clear: both;" />
                       </li>
                    </ul>
                </li>
             </ul>
         </div>
      </form>

我还在我的页面上导入了&lt;%@ Import Namespace="System.Configuration" %&gt;。在这里我想说我在我的页面上使用内联代码。感谢阅读问题并给我帮助。

【问题讨论】:

标签: asp.net vb.net inline


【解决方案1】:

出于安全原因,任何类型的应用设置都不能在视图范围内使用。

但是要暴露它们,有一个简单的解决方法。

 namespace MyApp {
     public static class SettingsExposer{
           public static string SecureUrl { 
                get { return System.Configuration.ConfigurationManager.AppSettings("SECURE_URL"); }
           }
     }
 }

在你的 HTML 中

<form action="<%=MyApp.SettingsExposer.SecureUrl%>" />

【讨论】:

  • 我正在使用内联代码,其中大部分代码都在我的表单上,所以我如何在表单操作中访问 System.Configuration.ConfigurationManager.AppSettings("SECURE_URL");
  • @Abhishek 也为您添加了表单操作。
猜你喜欢
  • 2018-02-24
  • 1970-01-01
  • 2013-12-06
  • 2018-03-07
  • 1970-01-01
  • 2016-02-02
  • 1970-01-01
  • 2014-09-15
  • 1970-01-01
相关资源
最近更新 更多