Tips Station Asp.net Article Seo Articles
Tutorials Code Samples
›  Home
›  Mission
›  About us
›  Contact Us
›  Feedback
›  Terms & Condition
Asp Articles
IT Solutions
 
› ASP.NET

› Programming Tips

› Ajax

› Asp

› ADO.NET

› Databases

› SEO

› CSS And Designing

› Php

 
Most Viewed Articles
 
› Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.

› Change theme dynamically without page refresh in ASP.NET

› Simple ASP Image Resize Function

› Install AJAX On Machines Running Visual Studio 2005

› ASP.Net Interview Questions And Their Answers

› Creating Pretty Popups Using AJAX

› Encode Url using ASP

› SQL Server Performance Counters

› .NET Data Access Performance Comparison

› UpdatePanel control in Asp.net Ajax

more...
 
 
Home> Programming Tips
 
Encrypt Applications Settings in Asp.Net
 

Encrypt your connections strings and application settings in code
You can encrypt the appSettings and connectionStrings sections of your web.config file via code when your application first starts. To do this, create a file named "global.asax" in your root directory and add this code to Application_Start method.

   <%@ Application Language="VB" %>  
    <%@ Import Namespace="System.Configuration" %>  
    <%@ Import Namespace="System.Web.Configuration" %>  
      
    <script runat="server">  
      
        Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)  
           ' Code that runs on application startup  
             
           ' Get the file path  
           Dim path As String = HttpContext.Current.Request.CurrentExecutionFilePath  
           path = path.Substring(0, path.LastIndexOf("/"))  
     
           ' Get the appSetting and connectionStrings sections  
           Dim config As System.Configuration.Configuration = WebConfigurationManager.OpenWebConfiguration(path)  
           Dim appSettings As ConfigurationSection = config.GetSection("appSettings")  
           Dim connectionSettings As ConfigurationSection = config.GetSection("connectionStrings")  
             
           ' Encrypt the appSettings and connectionStrings sections if they are not already protected  
           If appSettings.SectionInformation.IsProtected = False Then  
               appSettings.SectionInformation.ProtectSection("DataProtectionConfigurationProvider")  
               ' To unprotect this section, use:  
               'appSettings.SectionInformation.UnprotectSection()  
           End If  
           If connectionSettings.SectionInformation.IsProtected = False Then  
               connectionSettings.SectionInformation.ProtectSection("DataProtectionConfigurationProvider")  
               ' To unprotect this section, use:  
               'connectionSettings.SectionInformation.UnprotectSection()  
           End If  
             
           Try  
               config.Save()  
           Catch ex As Exception  
               ' If an error occurs, it is most likely a permissions error  
               ' so make sure the ASP.NET process account has write permissions for the web.config file  
           End Try  
       End Sub  

 

 
 
Vrp Technologies
 
Serversea Hosting
 
 
Latest Articles
 
› Sending SMS With PHP

› MySQL Join Tutorial

› Make An RSS Feed Using PHP

› Intro To Object: Option Variables

› Design An Online Chat Room With PHP And MySQL

› Create Tell A Friend Script With HTML & PHP

› Benchmark And Optimize PHP Script Speed

› What Kind of DBA Are You?

› SQL Server Performance Counters

› SQL Server Performance Tips

more...
 
Random Articles
 
› Understanding Transaction in ADO.NET

› Encrypt Applications Settings in Asp.Net

› Displaying Data using ASP.NET 2.0 DataList

› Generating Ms Excel file from GridView with ASP.NET

› Search Engine Friendly Web Design - 3 Ways To Use CSS

› Make An RSS Feed Using PHP

› Search Engine Optimization & Submission Strategies - A Beginners Guide

› MySQL Join Tutorial

› Cache Data within your Application - Asp.Net

› Successful CSS Template Skins

more...
 
Home Mission About us Contact us Feedback Terms Conditions
2008 © Copyright TipsStation. All rights reserved.