Thursday 13 April 2017

The Periodic Table Of SEO Success Factors


Visual studio shortcuts to improve your productivity

There are some useful shortcuts to improve your productivity while writing a code.

1) Format scattered and unaligned code

     CTRL + K + D


2) Comment code

     CTRL + K + C


3) Uncomment code

     CTRL + K + U

Tuesday 11 April 2017

Standard Naming Convention for ASP.NET and C#

For any programming language standard naming system is very import. It makes a complex system easy for others.Use these in your own projects and/or adjust these to your own needs.

There are different types of naming casing style. First let’s understand different types of casing styles.

Camel Case (camelCase): First letter of the word is lower case and then each first letter of the part of the word is upper case. Example: numberOfDays

Pascal Case (PascalCase): First letter of the word is upper case and then each first letter of the part of the word is upper case. Example: DataTable

Underscode Prefix (_underscore): The word begins with underscore singe and for the rest of the word use camelCase rule. Example: _strFirstName

Hungarian Notation: First letter of the word is about its data type and rest of the word is camelCase. Example: iStudentNumber (i=integer)


Uppercase: All letters of the word are uppercase. Example: ID, PI

How to write log file in c#?

Below is the function to create text log file in C#

public static void WriteLog(string strLog)
    {
        StreamWriter log;
        FileStream fileStream = null;
        DirectoryInfo logDirInfo = null;
        FileInfo logFileInfo;

        string logFilePath = "C:\\Logs\\";
        logFilePath = logFilePath + "Log-" + System.DateTime.Today.ToString("MM-dd-yyyy") + "." + "txt";          
        logFileInfo = new FileInfo(logFilePath);
        logDirInfo = new DirectoryInfo(logFileInfo.DirectoryName);
        if (!logDirInfo.Exists) logDirInfo.Create();
        if (!logFileInfo.Exists)
        {
            fileStream = logFileInfo.Create();
        }
        else
        {
            fileStream = new FileStream(logFilePath, FileMode.Append);
        }
        log = new StreamWriter(fileStream);
        log.WriteLine(strLog);
        log.Close();
    }  

Wednesday 5 April 2017

What is load balancing??

Load Balancing Structure


Load Balancing


Load balancing refers to efficiently distributing incoming network traffic across a group of back-end servers, also known as a server farm or server pool.

Saturday 1 April 2017

Cookie Helper Class in C#


In this article I will show you Cookie Helper Class in C#.


public static class CookieHelper
    {
        //Set new cookie...
        public static bool Set(string CkName, string CkValue, int CkExpirationMins, 
            string ckDomain, bool ckIsSecure)
        {
            bool flag = false;
            try
            {
                HttpCookie newCookie = new HttpCookie(CkName);
                newCookie.HttpOnly = true;
                newCookie.Value = CkValue;
                newCookie.Expires = DateTime.Now.AddMinutes(CkExpirationMins);
                if (!string.IsNullOrEmpty(ckDomain)) newCookie.Domain = ckDomain;
                if (ckIsSecure) newCookie.Secure = ckIsSecure;
 
                HttpContext.Current.Response.Cookies.Add(newCookie);
                flag = true;
            }
            catch (Exception)
            {
                flag = false;
            }
            return flag;
        }
 
        //Read cookie value...
        public static string Get(string CkName)
        {
            string strReturn = "";
            if (!string.IsNullOrEmpty(CkName))
            {
                try
                {
                    HttpCookie currentCookie = (HttpCookie)HttpContext.Current.Request.Cookies[CkName];
                    if (currentCookie != null) strReturn = currentCookie.Value;
                }
                catch (Exception) { }
            }
            return strReturn;
        }
 
    }