Showing posts from 2010

Best way to encrypt/decrypt querystring in .Net

Please find the best way to do Encryption/Decryption in .net. If you use standard way of accessing query string parameter values after encrypting or hashing you will get errors. Using following way, it will generate safe Encryption/Decryption in query string.

Encrypt :

    static string Encrypt(string originalString)
        if (String.IsNullOrEmpty(originalString))
            return string.Empty;
        DESCryptoServiceProvider cryptoProvider = new DESCryptoServiceProvider();
        MemoryStream memoryStream = new MemoryStream();
        CryptoStream cryptoStream = new CryptoStream(memoryStream,
            cryptoProvider.CreateEncryptor(bytes, bytes), CryptoStreamMode.Write);
        StreamWriter writer = new StreamWriter(cryptoStream);
        return Convert.ToBase64String(memoryStream.GetBuffer(), 0, (int)memoryStream.Length);

Access Session in HTTPHandler

If you wan to access session in your httphandler code, you can define your httphandler as follows.

public class SSOHandler : IHttpHandler, IRequiresSessionState


Selenium With .Net

Recently I had a chance to work with Selenium framwork. It is pretty easy to intrgrate automated testing into .net with Selenium. Also for project like web site scrapping and automated posting, can be easily developped with few lines of code. Following code lines will automate a web site login with use of selenium framework.

ISelenium selenium = new DefaultSelenium(seleniumServer, port, browser, website);
selenium.WaitForPageToLoad((ConfigLoader.Configurations.WaitingTime * 1000).ToString());
selenium.Type("ctl00_PageContent_UserName", ConfigLoader.Configurations.UserName);
selenium.Type("ctl00_PageContent_Password", ConfigLoader.Configurations.Password);
selenium.WaitForPageToLoad((ConfigLoader.Configurations.WaitingTime * 1000).ToString());

Error in parsing Convert.ToDouble or double.Parse for decimal values in C#

I found that one of my client's application showing "0,00" for pricing column of his application, and found that it works find on my pc. Once I traced the error, I found that it fails when parsing price like "1500.00" with Convert.ToDouble or double.Parse. The reason for that is, the particular client using Finnish currency format, which is like "1500,00". As you see the difference is they use "," instead of "." for decimal separation. If you want to convert decimal (money) values in string format, which will universally work in every where, you have to use following code snippet.

            string pricetext = "5535.25";
            string[] parts = pricetext.Split('.');
            double price = Convert.ToDouble(parts[0]);
            if (parts.Length == 2)
                dec = Convert.ToInt32(parts[1]);
                price += (dec * 0.01);

Configuring Sharepoint Sever 2007

Working on configuring sharepoint server 2007 in windows server 2003. Having issue in connecting a separate DB server with sharepoint server using domain admin account. Does anyone have idea, how to do it?

Handling Exit Event of Console Application in C#

Do you wan to do something on the exit event of Console Application. .Net framework does not provide such direct event to do that. You can use following workaround to have that kind of event in your application.

        static void Main(string[] args)
            HandlerRoutine hr = new HandlerRoutine(Handler);
            SetConsoleCtrlHandler(hr, true);


        public static void DoOnAppExit()
                  //Do something......

        #region Handle App Exit

        static Boolean Handler(CtrlTypes CtrlType)
            // A switch to handle the event type.
            switch (CtrlType)
                case CtrlTypes.CTRL_C_EVENT:
                case CtrlTypes.CTRL_BREAK_EVENT:
                case CtrlTypes.CTRL_CLOSE_EVENT:
                case CtrlTypes.CTRL_LOGOFF_EVENT:
                case CtrlTypes.CTRL_SHUTDOWN_EVENT:

My Web in limeweb

I deployed my new web site in limeweb. It is free and easy to use.

WCF Client with HTTPS enabled and Authentication

Following code sample shows how WCF client can be used with WCF service running on HTTPS and secure with authentication.

        // Create the binding.
        WSHttpBinding myBinding = new WSHttpBinding();
        myBinding.Security.Mode = SecurityMode.Transport;
        myBinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic;

        // Create the endpoint address.
        EndpointAddress ea = new  EndpointAddress("");

        // Create the client.
        TestServiceClient cc =   new TestServiceClient(myBinding, ea);
        // The client must provide a user name and password.
        cc.ClientCredentials.UserName.UserName = "uname";
        cc.ClientCredentials.UserName.Password = "pwd";
            // Begin using the client.


            // Close the client.
        catch (Exc…

Cannot see None English characters (ANSI Encoded) in .Net controls when loading form files

Do you have problems with showing non English characters in .net controls ? If you have seen non English characters are shown as "?" in .Net controls when you load contents from files. That is because of the encoding issue. You have use "Encoding.Default" to solve this issue when you read from file.


javasripts in ActiveX doesn't work properly in IE8

Recently I experienced with that, some javascripts in ActiveX are blocked in IE8 which were working in IE6 and IE7. Once I added the domain to trusted site in IE8, those scripts are working as earlier. If you have same issue, please go to Tools > Option > Security > trusted sites and add the domain you want. Then refresh the browser. That's it. I think this will help some one having issues with ActiveX in IE8.

Light Weight Web Chat in ASP.NET

I have completed POC on light weight web chat, which can be easily integrate to any ASP.NET web site with little effort. It is fully driven on Ajax asynchronous calls. So bandwith usage will be very less. It is suitable for medium size web sites.

Twitter API Integration

Successfully completed twitter integration with OAuth implementation in is realy helpful when you want implemnt OAuth.
Working on completing the Smart Downloader. Fixing some bugs found. Planing for next release with advanced installer.