Thursday, July 21, 2011

"Set Service Login" window during service installation from InstallUtil.exe

Often a prompt window named "Set Service Login" appears during windows service installation through "installUtil.exe" asking for user authentication

Best way to ignore it is by modifying properties in installer.cs class

-Change Account in ProcessInstaller to 'LocalSystem'
-And Start type in ServiceInstaller to 'Automatic'

It will work fine than.

Debugging a windows Service

Though there are different ways to debug your code in windows service, I have often preferred to modify my default Program.cs class like:


static class Program
{
///
/// The main entry point for the application.
///

static void Main()
{
#if (!DEBUG)
ServiceBase[] ServicesToRun;
ServicesToRun = new ServiceBase[]
{
new LISService()
};
ServiceBase.Run(ServicesToRun);
#else
LISService lis = new LISService();
lis.Start();
#endif
}
}

Monday, May 30, 2011

Copy Assembly from GAC

An easy way to copy library file from GAC is to access C:\windows\assembly\GAC_MSIL from run command.

Monday, April 18, 2011

Copy on Clipboard using Javascript

I needed to have functionality of copying contents of textbox on clipboard at my aspx page. This is how I implement it

Objects:

Width="596px">


Script:
function CopyToClipboard()
{
var textboxVal = document.getElementById("txtScript").value; //txtText id of a textbox
if( window.clipboardData && clipboardData.setData )
{
clipboardData.setData("Text", textboxVal);
}
else
{
//alert("You should upgrade you browser,works only in IE4+");
}
}

Thursday, February 17, 2011

Disable an ASP.NET validation from Javascript

Below is a small code i used to disable my dotnet validators through javascript
var myVal = document.getElementById('MyvalidatorsClientId');
ValidatorEnable(myVal, false);

where ValidatorEnable(Object, Enabled).

A sample could be
function CountryChanged()
{
var myVal = document.getElementById('ctl00_ContentPlaceHolder1_RfvtxtState');
ValidatorEnable(myVal, false);
}

Tuesday, January 18, 2011

Generate Random Alphanumeric Number

I used the following function to generate random alphanumeric code in one of my project

Public Shared Function GenerateRandomString(ByRef len As Integer, ByRef upper As Boolean) As String
Dim rand As New Random()
Dim allowableChars() As Char = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLOMNOPQRSTUVWXYZ0123456789".ToCharArray()
Dim final As String = String.Empty
For i As Integer = 0 To len - 1
final += allowableChars(rand.Next(allowableChars.Length - 1))
Next
Return IIf(upper, final.ToUpper(), final)
End Function

Thursday, December 9, 2010

Encrypted Connection Strings using aspnet_regiis.exe

I had a task to encrypt connectionstrings of a project, i decided to use aspnet_regiis.exe file which i studied for my MCTS certification paper

Using Visual Studio Command Prompt,

Encrypt ConnectionString
[Generic form for encrypting the Web.config file for a particular website]
Inorder to encrypt specifying a path to physical directory
aspnet_regiis.exe -pef section physical_directory –prov provider
-- OR --
In order to encrypt with the name of virtual directory
aspnet_regiis.exe -pe section -app virtual_directory –prov provider

Example:
aspnet_regiis.exe -pef "connectionStrings" "D:\Publish\MyProject\1" –prov "DataProtectionConfigurationProvider"
-- OR --
aspnet_regiis.exe -pe "connectionStrings" -app "/MySite" –prov "DataProtectionConfigurationProvider"
*Note: This will add encrypteddata, cipherdata, ciphervalue tags in connectionstrings tag
----------------------------------
Decrypt ConnectionString
[Generic form for decrypting the Web.config file for a particular website]
Inorder to decrypt specifying a path to physical directory
aspnet_regiis.exe -pdf section physical_directory
-- OR --
Inorder to decrypt with the name of virtual directory
aspnet_regiis.exe -pd section -app virtual_directory

Example:
aspnet_regiis.exe -pdf "connectionStrings" "D:\Publish\MyProject\1"
-- OR --
aspnet_regiis.exe -pd "connectionStrings" -app "/MySite"
*Note: No provider is required for decryption as it will pick from webconfig file itself

Happy Dotnetting!~