Monday, June 15, 2015

Reading a value from the Web.config file of an ASP .NET Web Application using Javascript

To read a value from the web.config file of an ASP .NET Web Application using javascript, you can do the following:

  1. In your web.config file, add a new <appSettings> with the key and value that you wish for the javascript code to obtain.  In this example, here is the new <appSettings> node, I'm going to reference:

    <appSettings>
         <add key="Environment" value="TEST" />
    </appSettings>


  2. In the HTML code of my default.aspx page, I'm going to add the following javascript function that's going to reference the new <appSettings> node that I just added:

    function getEnvironment() { 
         var environment = '<%= ConfigurationManager.AppSettings["Environment"].ToString() %>';
         alert(environment);
    }
All you have to do is call this function at an appropriate location in your code and it will obtain the value of the respective <appSettings> node.  Naturally, you'll want to swap out the alert call with some valid code, but the idea of this example is to get you rolling.

Friday, June 12, 2015

Reseeding the Primary Key/ID column of a SQL Table

If you ever need to remove all the records from a SQL database table and then reseed/reset the value of the primary key/ID column, here are the Transact-SQL queries that you can use:

USE [DatabaseName]
TRUNCATE TABLE [TableName]
DBCC CHECKIDENT ("TableName", RESEED, 1);