Tuesday, June 17, 2014

use httpcontext and server mappath in a c# class library

1) add using System.Web;

2)string  filePath = HttpContext.Current.Server.MapPath("~/TextFiles/StylePath.txt");

Monday, June 16, 2014

Access asp.net session value in javascript

 var Guest = '<%=HttpContext.Current.Session["Advisorguest"]%>';

Common Logic For Getting Single Value From Database Asp.Net

1)  string[,] param1 = new string[1, 2];
                param1[0, 0] = "@userName";
                param1[0, 1] = username;

2) string status = CommonClass.Common.Instance.getSingleValue("checkIsExistUserName", param1);

3)  SqlConnection myConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["ValweaveFa"].ConnectionString);
        SqlCommand sm;
public string getSingleValue(string procNm, string[,] paramVal)
        {
            try
            {
                myConnection.Open();
                sm = new SqlCommand(procNm, myConnection);
                sm.CommandType = CommandType.StoredProcedure;

                for (int i = 0; i < paramVal.Length / 2; i++)
                {
                    if ((paramVal[i, 0] != null) && (paramVal[i, 1] != null))
                        sm.Parameters.Add(paramVal[i, 0], paramVal[i, 1]);
                }
                string Password = Convert.ToString(sm.ExecuteScalar());
                myConnection.Close();
                return Password;

            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

Thursday, June 12, 2014

Always Add Two connection strings in ASP.NET Web.config

1) <add name="read" connectionString="Data Source=Test\SQLEXPRESS;Initial Catalog=DatabaseName;Integrated Security=false;uid=userid; password=password#123; Persist Security Info=True;" providerName="System.Data.SqlClient"/>

Use This Connection string for Read data from database

2) <add name="readandwrite" connectionString="Data Source=Test1\SQLEXPRESS;Initial Catalog=DatabaseName;Integrated Security=false;uid=userid1; password=password#1234; Persist Security Info=True;" providerName="System.Data.SqlClient"/>

Use This for Read and write data from and to database

3) With use of this performance will get better.

4)  TO get better Security

Tuesday, June 10, 2014