public UserContext UserAuthenticate(string userId, string password) { UserContext userContext = null; DataBaseUtility db = new DataBaseUtility(); SqlConnection con = null; try { string query = "select u.Id,u.UserId,r.RoleType from dbo.Users u , Role r where u.UserId=" + SQLUtility.getString(userId) + " and u.Password="******" and r.Id = u.RoleId"; con = db.OpenConnection(); log.Info(" connection string " + con.ConnectionString); SqlCommand comd = db.getSQLCommand(query, con); SqlDataReader reader = comd.ExecuteReader(); if (reader.Read()) { userContext = new UserContext(); userContext.Id = ValidationUtility.ToInteger(reader[0].ToString()); userContext.UserId = reader[1].ToString(); userContext.Role = reader[2].ToString(); } reader.Close(); comd.Dispose(); } catch (Exception ex) { log.Error("Exception in UserAuthenticate Method ", ex); } finally { db.CloseConnection(con); } if (userContext != null) { CallWebService service = new CallWebService(); if (!service.CheckUserIsValid()) { userContext = null; } } return userContext; }
public void PreRequestHandlerExecute(object sender, EventArgs e) { var context = ((HttpApplication)sender).Context; if (ValidationUtility.IsEqual("/", context.Request.CurrentExecutionFilePath) || ValidationUtility.IsEqual("/Home", context.Request.CurrentExecutionFilePath) || context.Request.CurrentExecutionFilePath.ToString().StartsWith("/Content") || context.Request.CurrentExecutionFilePath.ToString().StartsWith("/Scripts")) { } else { CallWebService service = new CallWebService(); if (!service.CheckUserIsValid()) { context.Response.Redirect("/Home"); } } //else //{ // CallWebService service = new CallWebService(); // if (!service.CheckUserIsValid()) // { // context.Response.Redirect("/Home"); // } //} //log.Info("Call PreRequestHandlerExecute Method"); //if (ValidationUtility.IsEqual("/", context.Request.CurrentExecutionFilePath) || ValidationUtility.IsEqual("/Home", context.Request.CurrentExecutionFilePath)) //{ //} //else //{ // CallWebService service = new CallWebService(); // if (!service.CheckUserIsValid()) // { // context.Response.Redirect("/Home"); // } //} //UserContext cont = new UserContext(); //if (cont == null && (ValidationUtility.IsEqual("/Login/Authenticate", context.Request.CurrentExecutionFilePath) || ValidationUtility.IsEqual("/", context.Request.CurrentExecutionFilePath))) //{ //} //else if (cont==null) //{ // context.Response.Redirect("http://www.google.com"); //} //if (context.Session["UserContext"] != null) //{ // log.Info("Session is not null"); //} //else //{ // if (!ValidationUtility.IsEqual("/Login/Authenticate", context.Request.CurrentExecutionFilePath) || !ValidationUtility.IsEqual("/", context.Request.CurrentExecutionFilePath)) // { // } // else // { // }} }