Monday, March 31, 2014

Friday, March 28, 2014

encrypt decrypt webconfig connectionStrings from codebehind in asp.net | Secure web config Connection Strings with RSACryptoServiceProvider Class through coding in asp.net

hi in this post i will show how to secure connection strings inside a web.config file from code in asp.net.

1. code to encrypt :

      protected void Encrypt_Click(object sender, EventArgs e)
    {
        string provider = "RSAProtectedConfigurationProvider";
        string section = "connectionStrings";
        Configuration confg = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration(Request.ApplicationPath);
        ConfigurationSection configSect = confg.GetSection(section);
        if (configSect != null)
        {
            configSect.SectionInformation.ProtectSection(provider);
            confg.Save();
        }
    }

web.config


2. code to decrypt :

    protected void Button2_Click(object sender, EventArgs e)
    {
        string section = "connectionStrings";
        Configuration config = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration(Request.ApplicationPath);
        ConfigurationSection configSect = config.GetSection(section);
        if (configSect.SectionInformation.IsProtected)
        {
            configSect.SectionInformation.UnprotectSection();
            config.Save();
        }
    }

web.config


Using Javascript to create a Datatime picker control in Html

hi in this post lets c how to create a datetime picker in html using Javascript.

1. download the js file using this url.

http://www.javascriptkit.com/script/script2/datetimepick.zip

2. After u download this extract the zip file and after extracting add the .js and image files into your project.

3. Below is the implementation code, you can also get the sample code in the zip file downloaded.

<!DOCTYPE html>
<html>
<head>

<script language="javascript" type="text/javascript" src="datetimepicker.js">
</script>

</head>
<body>
 
<input type="Text" id="date1" maxlength="25" size="25">

Select a Date : <a href="javascript:NewCal('date1','ddmmmyyyy',true,24)"><img src="images/cal.gif" width="20" height="18"></a>

</body>
</html>

4. Output:





Friday, March 7, 2014