0

i want to read appsetting from web.config file on my aspx page but this is not success that i try . What i doing wrong here

Below is my web.config setting

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

And Below is aspx page part where want to read this

<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>

i also import the <%@ Import Namespace="System.Configuration" %> on my page. Here i want to say that i am using inline code on my page . Thanks to read question and give me help .

Abhishek
  • 319
  • 8
  • 23
  • http://stackoverflow.com/questions/685259/getting-configuration-settings-from-web-config-app-config-using-class-library – Nagaraj S Jan 22 '14 at 06:13

1 Answers1

1

For security reasons app settings of any kind aren't available in the scope of views.

But to expose them there's an easy work around.

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

And in your HTML

<form action="<%=MyApp.SettingsExposer.SecureUrl%>" />
siva.k
  • 1,344
  • 14
  • 24
  • I am using inline code where most of the code is on my form so how i can access that `System.Configuration.ConfigurationManager.AppSettings("SECURE_URL");` on form action – Abhishek Jan 22 '14 at 07:37
  • @Abhishek added the form action for you as well. – siva.k Jan 22 '14 at 16:46