I worked on a very small ASP .net application this week end to test the OAuth consumer library sharpOauth against the Twitter API. When working with OAuth, there are at least two values that need to be stored in the configuration file : the consumerKey and the consumerSecret. When working in ASP .net 2.0, here is how to do it

  1. Add the values in the configuration file of the application named web.config (code 1)
  2. Add a reference to your application and select System > Configuration (figure 1)
  3. Add the statement using System.Configuration in your code
  4. Use the ConfigurationManager to retrieve the configuration value (code 2)

#Code 1

1
2
3
4
5
6
...
</system.web>
<appSettings>
<add key="consumerKey" value="xX1234xxxxXXxx432" />
<add key="consumerSecret" value="xxXXX1256436xxxXx" />
</appSettings>

#Figure 1

#Code 2

1
2
oauthConfig.ConsumerKey = ConfigurationManager.AppSettings.Get("consumerKey");
oauthConfig.ConsumerSecret = ConfigurationManager.AppSettings.Get("consumerSecret");
Filed under: Computing, Development, Dot Net

Tagged with: , , , ,

Liked this page?

Tweet it

Subscribe to the RSS feed or sign up for the newsletter now.

Posts related to Using the web.config file in ASP .net

2 Comments to "Using the web.config file in ASP .net"

  1. Comment by Monmohan sharma on February 28, 2011 at 12:44 pm Reply

    If you want to know a little bit of advanced use of Web.config file with snap shot, visit this.

    • Comment by shalfon on February 28, 2011 at 9:44 pm Reply

      Thanks for sharing this link, great post.

Name (required)

Email (required)

Website

Leave a Reply

  • About Me


    photo of Samantha Halfon Samantha Halfon
    Software Engineer
    blueKiwi software
    Paris, France
    I enjoy playing with my computer(s), listening to Bob Dylan (and related artists) and watching movies (especially if they were directed by Martin Scorsese or John Cassavetes). Sometimes, I play a little guitar... If not doing any of the above, I am either riding a small red bike around Paris, or, making videos. About my videomaking please check out World Wide Angle and its blog.