Results 1 to 3 of 3

Thread: Use String From Web Config

  1. #1

    Thread Starter
    Hyperactive Member kleptos's Avatar
    Join Date
    Aug 2001
    Location
    The Dark Carnival
    Posts
    346

    Use String From Web Config

    In my web.config file i have a key that i use called AppTitle, in this key i have the title of my web application. Because it may change a few times i decided to add the key to my web.config. Here is my problem, how do i take that key and use it as text on my web page? I want to add that string into the <title></title> part of my aspx page. How can i do this so i can use the web.config key in the title of my page. Thanks!
    ..::[kleptos]::..
    • Database Administrator (MSSQL 2000)
    • Application Developer (C#)
    • Web Developer (ASP.NET)


  2. #2
    Hyperactive Member
    Join Date
    Dec 2001
    Location
    Dublin, Ireland
    Posts
    262
    First off make sure you have the key in the correct place:-

    VB Code:
    1. <configuration>
    2.   <appSettings>
    3.     <add key="AppName" value="whatever" />
    4.   </appSettings>
    5.   <system.web>
    6.   rest of web.config as normal.....

    Now declare string variable in your page class and get the value:-

    VB Code:
    1. Public Class WebForm1
    2.     Inherits System.Web.UI.Page
    3.     Public AppName as String = ConfigurationSettings.AppSettings("AppName")
    4.  
    5.     Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    6.        etc.....

    Finally your html will look like this:-

    <title><%=AppName %></title>

  3. #3

    Thread Starter
    Hyperactive Member kleptos's Avatar
    Join Date
    Aug 2001
    Location
    The Dark Carnival
    Posts
    346
    Very cool....
    Thank You
    ..::[kleptos]::..
    • Database Administrator (MSSQL 2000)
    • Application Developer (C#)
    • Web Developer (ASP.NET)


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width