public string getDatosQueryFirst(string _cID, string _type) { var ds = new DataSet("dataSet"); ds.Namespace = "PivotData"; try { if (HttpContext.Current.User.Identity.IsAuthenticated) { id = (System.Web.Security.FormsIdentity)HttpContext.Current.User.Identity; int usuID = Convert.ToInt32(id.Ticket.UserData); using (var cnn = Conexion.SqlConnection()) { using (var da = new SqlDataAdapter("uspPivotData", cnn)) { da.SelectCommand.CommandType = CommandType.StoredProcedure; da.SelectCommand.Parameters.Add("@usuID", SqlDbType.VarChar).Value = usuID; da.SelectCommand.Parameters.Add("@cID", SqlDbType.VarChar).Value = _cID; da.Fill(ds); } } if (ds.Tables[0].Rows.Count > 0) { string json = JsonConvert.SerializeObject(ds, Formatting.Indented); return(json); } } return("[{resultado: 'No'}]"); } catch (Exception ex) { return("[{resultado: 'No'}]"); } }
public IEnumerable <SelectListItem> DistrictAuth(string cRegion, string selectedValue) { System.Web.Security.FormsIdentity identity = (System.Web.Security.FormsIdentity)HttpContext.User.Identity; string[] roles = identity.Ticket.UserData.Split('|'); if (roles.Length > 4) { IMsDistrictAuthorizationQuery msDistrictAuthorizationQuery = new MsDistrictAuthorizationListQuery(); IList <MsDistrictAuthorizationDto> listDistrictAuth = msDistrictAuthorizationQuery .GetMsDistrictAuthorizationQRY(2, 0, 0 , "cStatus = 1 AND nPernr = " + roles[5] + " AND cRegionCode = '" + cRegion + "'" , "cDistrictName"); IEnumerable <SelectListItem> query = (from da in listDistrictAuth select new SelectListItem { Value = da.cDistrictCode, Text = da.cDistrictName, Selected = da.cDistrictCode.Equals(selectedValue) ? true : false }); return(query); } return(null); }
public ActionResult Details(int id) { #region User identification System.Security.Principal.IIdentity context = HttpContext.User.Identity; int user = 0; if (context.IsAuthenticated) { System.Web.Security.FormsIdentity ci = (System.Web.Security.FormsIdentity)HttpContext.User.Identity; string[] userRole = ci.Ticket.UserData.Split('|'); user = int.Parse(userRole[0]); } #endregion ProcessDocumentBiz processDocumentBiz = new ProcessDocumentBiz(); Process process = processBiz.GetProcessbyKey(new Process() { id = id }); vmProcess oProcess = new vmProcess() { id = id, nombre = process.nombre, descripcion = process.descripcion, archivoCaracterizacion = process.archivoCaracterizacion }; ActivityLogBiz.SaveActivityLog(new ActivityLog() { idUsuario = user, accion = "Proceso " + process.nombre, fecha = DateTime.Now }); oProcess.lstDocumentType = processDocumentBiz.GetDocumentTypeByProcess(process); return(View(oProcess)); }
public IEnumerable <SelectListItem> ProvinceAuth(string selValue) { System.Web.Security.FormsIdentity identity = (System.Web.Security.FormsIdentity)HttpContext.User.Identity; string[] roles = identity.Ticket.UserData.Split('|'); selValue = string.IsNullOrEmpty(selValue) ? string.Empty : selValue; if (roles.Length > 4) { IMsDistrictAuthorizationQuery msDistrictAuthorizationQuery = new MsDistrictAuthorizationListQuery(); IList <MsDistrictAuthorizationDto> listDistrictAuth = msDistrictAuthorizationQuery .GetMsDistrictAuthorizationQRY(2, 0, 0, "cStatus = 1 AND nPernr = " + roles[5], "cProvince"); IEnumerable <SelectListItem> query = (from da in listDistrictAuth group da by new { da.cProvince } into g select new SelectListItem { Value = g.FirstOrDefault().cProvince, Text = g.FirstOrDefault().cProvince, Selected = selValue.Equals(g.FirstOrDefault().cProvince) }); return(query); } return(null); }
protected void Application_AuthenticateRequest(Object sender, EventArgs e) { HttpApplication app = (HttpApplication)sender; HttpContext ctx = app.Context; //获取本次Http请求的HttpContext对象 if (ctx.User != null) { #region 每次请求的请求信息写入日志 string msg = string.Format(@"{0} URL:{1} REFER:{2} USER:{3} 用户IP:{4} ", "请求信息======", ctx.Request.Url.ToString(), ctx.Request.UrlReferrer != null ? ctx.Request.UrlReferrer.ToString() : "NULL", ctx.User.Identity.IsAuthenticated ? ctx.User.Identity.Name : "NOT AUTH", ctx.Request.UserHostAddress); logger.Debug(msg); #endregion if (ctx.Request.IsAuthenticated == true) //验证过的一般用户才能进行角色验证 { System.Web.Security.FormsIdentity fi = (System.Web.Security.FormsIdentity)ctx.User.Identity; System.Web.Security.FormsAuthenticationTicket ticket = fi.Ticket; //取得身份验证票 string userData = ticket.UserData; // logger.Debug("从UserData中恢复role信息=====" + userData); string[] roles = userData.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); //将角色数据转成字符串数组,得到相关的角色信息 ctx.User = new System.Security.Principal.GenericPrincipal(fi, roles); //这样当前用户就拥有角色信息了 } } }
public void CheckRoleMenu() { if (Request.IsAuthenticated) { if (TempData["RoleMenu"] == null) { System.Web.Security.FormsIdentity identity = (System.Web.Security.FormsIdentity)HttpContext.User.Identity; string[] roles = identity.Ticket.UserData.Split('|'); //Role IMsUserAccessesQuery Query = new MsUserAccessesListQuery(); IList <MsGroupAccessViewModel> lst = Query.GetRightsRole(roles[4], roles[1]); TempData["RoleMenu"] = lst; } TempData.Keep("RoleMenu"); } // TempData.Keep("RoleMenu"); IList <MsGroupAccessViewModel> lstGA = (IList <MsGroupAccessViewModel>)TempData["RoleMenu"]; var path = Request.Path.ToString(); if (lstGA != null) { var Found = from x in lstGA where x.RoleName == MenuRoles.ADD && x.MenuItem == path select x; TempData[MenuRoles.ADD] = "disabled"; if (Found.Count() > 0) { // ViewData.Add(key, "dis"); TempData[MenuRoles.ADD] = ""; } TempData.Keep(MenuRoles.ADD); } foreach (string key in MenuRoles.ALL.Except(new[] { MenuRoles.ADD })) { if (lstGA != null) { var Found = from x in lstGA where x.RoleName == key && x.MenuItem == path select x; TempData[key] = "sr-only"; if (Found.Count() > 0) { // ViewData.Add(key, "dis"); TempData[key] = "dis"; } TempData.Keep(key); } } }
/// <summary> /// Creates a graywulf principal based on the guid stored in the /// forms authentication token. /// </summary> /// <param name="identity"></param> /// <returns></returns> public static GraywulfPrincipal Create(System.Web.Security.FormsIdentity formsIdentity) { var identity = new GraywulfIdentity() { Protocol = Constants.ProtocolNameForms, Identifier = formsIdentity.Name, IsAuthenticated = true, }; identity.UserProperty.Name = formsIdentity.Name; return(new GraywulfPrincipal(identity)); }
protected static string UserRoles() { string roles = null; if (HttpContext.Current.User != null) { if (HttpContext.Current.User.Identity.IsAuthenticated == true) //验证过的一般用户才能进行角色验证 { System.Web.Security.FormsIdentity fi = (System.Web.Security.FormsIdentity)HttpContext.Current.User.Identity; System.Web.Security.FormsAuthenticationTicket ticket = fi.Ticket; //取得身份验证票 string userData = ticket.UserData; //从UserData中恢复role信息 roles = userData; //userData.Split(','); //将角色数据转成字符串数组,得到相关的角色信息 } } return(roles); }
protected void Application_AuthenticateRequest(Object sender, EventArgs e) { HttpApplication app = (HttpApplication)sender; HttpContext ctx = app.Context; //获取本次Http请求的HttpContext对象 if (ctx.User != null) { if (ctx.Request.IsAuthenticated == true) //验证过的一般用户才能进行角色验证 { System.Web.Security.FormsIdentity fi = (System.Web.Security.FormsIdentity)ctx.User.Identity; System.Web.Security.FormsAuthenticationTicket ticket = fi.Ticket; //取得身份验证票 string userData = ticket.UserData; //从UserData中恢复role信息 string[] roles = userData.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); //将角色数据转成字符串数组,得到相关的角色信息 ctx.User = new System.Security.Principal.GenericPrincipal(fi, roles); //这样当前用户就拥有角色信息了 } } }
protected static int UserID() { int userID = 0; if (HttpContext.Current.User != null) { if (HttpContext.Current.User.Identity.IsAuthenticated == true) //验证过的一般用户才能进行角色验证 { System.Web.Security.FormsIdentity fi = (System.Web.Security.FormsIdentity)HttpContext.Current.User.Identity; System.Web.Security.FormsAuthenticationTicket ticket = fi.Ticket; //取得身份验证票 userID = int.Parse(ticket.Name); } } //return userID; //程序调试阶段默认userid=3 return(3); }
protected override void OnAuthentication(AuthenticationContext filterContext) { if (filterContext.ActionDescriptor.ActionName.ToLower() == "edit") { var unAuthResult = new ContentResult { Content = "<html><head></head><body><div><h1 style=\"text-align: center;vertical-align: middle;height: 100px;line-height: 100px;color: red;\">当前页面需要验证权限,您需要登录才能访问!</h1></div></body></html>" }; var current_user = System.Web.HttpContext.Current.Session["current_user"]; if (current_user != null) { var user = (Ywl.Data.Entity.Models.User)current_user; if (user == null) { filterContext.Result = unAuthResult; } else { if (user.Account != "admin") { filterContext.Result = unAuthResult; } else { // base.OnAuthentication(filterContext); string[] roles = null; var ticket = new System.Web.Security.FormsAuthenticationTicket(user.Id.ToString(), false, 1); System.Security.Principal.IIdentity identity = new System.Web.Security.FormsIdentity(ticket); System.Security.Principal.IPrincipal principal = new System.Security.Principal.GenericPrincipal(identity, roles); //HttpContext.Current.User = principal; filterContext.Principal = principal; } } } else { filterContext.Result = unAuthResult; } } else { base.OnAuthentication(filterContext); } }
public string GetUserGroup() { if (Request.IsAuthenticated) { System.Web.Security.FormsIdentity identity = (System.Web.Security.FormsIdentity)HttpContext.User.Identity; string[] roles = identity.Ticket.UserData.Split('|'); if (roles.Length > 3) { return(roles[3]); } return(""); } else { return(""); } }
public string[] GetUserDistricts() { if (Request.IsAuthenticated) { System.Web.Security.FormsIdentity identity = (System.Web.Security.FormsIdentity)HttpContext.User.Identity; string[] roles = identity.Ticket.UserData.Split('|'); if (roles.Length > 9) { return(roles[9].Split(',')); } return(new string[0]); } else { return(new string[0]); } }
protected void Application_AuthenticateRequest(Object sender, EventArgs e) { bool User = HttpContext.Current.User != null; bool Auth = User && HttpContext.Current.User.Identity.IsAuthenticated; bool isIdentity = Auth && HttpContext.Current.User.Identity is System.Web.Security.FormsIdentity; if (isIdentity) { System.Web.Security.FormsIdentity id = (System.Web.Security.FormsIdentity)HttpContext.Current.User.Identity; System.Web.Security.FormsAuthenticationTicket ticket = id.Ticket; string[] role = new string[1]; role[0] = ticket.UserData; HttpContext.Current.User = new System.Security.Principal.GenericPrincipal(id, role); } }
public int GetUserPernr() { if (Request.IsAuthenticated) { System.Web.Security.FormsIdentity identity = (System.Web.Security.FormsIdentity)HttpContext.User.Identity; string[] roles = identity.Ticket.UserData.Split('|'); if (roles.Length > 5) { return(int.Parse(roles[5])); } return(0); } else { return(0); } }
public string setProdCanjes(string _cID, string _type, string _nombre, string _Desc, string _MarcaID, string _catID, string _pts, string _costo, string _obs) { var ds = new DataSet("dataSet"); ds.Namespace = "ProductosCanje"; try { if (HttpContext.Current.User.Identity.IsAuthenticated) { id = (System.Web.Security.FormsIdentity)HttpContext.Current.User.Identity; int usuID = Convert.ToInt32(id.Ticket.UserData); using (var cnn = Conexion.SqlConnection()) { using (var da = new SqlDataAdapter("uspGetProdCanjeList", cnn)) { da.SelectCommand.CommandType = CommandType.StoredProcedure; da.SelectCommand.Parameters.Add("@usuID", SqlDbType.VarChar).Value = usuID; da.SelectCommand.Parameters.Add("@cID", SqlDbType.VarChar).Value = _cID; da.SelectCommand.Parameters.Add("@type", SqlDbType.VarChar).Value = _type; da.SelectCommand.Parameters.Add("@Nombre", SqlDbType.VarChar).Value = _nombre; da.SelectCommand.Parameters.Add("@Desc", SqlDbType.VarChar).Value = _Desc; da.SelectCommand.Parameters.Add("@MarcaID", SqlDbType.VarChar).Value = _MarcaID; da.SelectCommand.Parameters.Add("@CatID", SqlDbType.VarChar).Value = _catID; da.SelectCommand.Parameters.Add("@Pts", SqlDbType.VarChar).Value = _pts; da.SelectCommand.Parameters.Add("@Costo", SqlDbType.VarChar).Value = _costo; da.SelectCommand.Parameters.Add("@Obs", SqlDbType.VarChar).Value = _obs; da.Fill(ds); } } if (ds.Tables[0].Rows.Count > 0) { string json = JsonConvert.SerializeObject(ds, Formatting.Indented); return(json); } } return("[{resultado: 'No'}]"); } catch (Exception ex) { return("[{resultado: 'No'}]"); } }
public string uspPivotAdd(string _regID, string _type, string _nombre, string _desc, string _orden, string _vID) { var ds = new DataSet("dataSet"); try { if (HttpContext.Current.User.Identity.IsAuthenticated) { id = (System.Web.Security.FormsIdentity)HttpContext.Current.User.Identity; int usuID = Convert.ToInt32(id.Ticket.UserData); using (var cnn = Conexion.SqlConnection()) { using (var da = new SqlDataAdapter("uspPivotAdd", cnn)) { da.SelectCommand.CommandType = CommandType.StoredProcedure; da.SelectCommand.Parameters.Add("@regID", SqlDbType.VarChar).Value = _regID; da.SelectCommand.Parameters.Add("@usuID", SqlDbType.VarChar).Value = usuID; da.SelectCommand.Parameters.Add("@tipo", SqlDbType.VarChar).Value = _type; da.SelectCommand.Parameters.Add("@nombre", SqlDbType.VarChar).Value = _nombre; da.SelectCommand.Parameters.Add("@descripcion", SqlDbType.VarChar).Value = _desc; da.SelectCommand.Parameters.Add("@orden", SqlDbType.VarChar).Value = _orden; da.SelectCommand.Parameters.Add("@vID", SqlDbType.VarChar).Value = _vID; da.Fill(ds); } } if (ds.Tables[0].Rows.Count > 0) { string json = JsonConvert.SerializeObject(ds, Formatting.Indented); return(json); } } return("[{resultado: 'No'}]"); } catch (Exception ex) { return("[{resultado: 'No'}]"); } }
protected override void OnActionExecuting(ActionExecutingContext ctx) { base.OnActionExecuting(ctx); sessionManager = new SessionManager(this.HttpContext.Session); if (sessionManager.User == null) { //if the user was loaded from a auth cookie, grab the user name from it and load the user details, and place it in the session variable var identity = HttpContext.User.Identity as System.Security.Principal.IIdentity; if (identity != null) { System.Web.Security.FormsIdentity fi = identity as System.Web.Security.FormsIdentity; if (fi != null) { DatabaseInterface db = new DatabaseInterface(); var user = db.GetUserById(new ObjectId(fi.Name)); if (user != null) { sessionManager.User = user; } } } } }
/// <summary> /// Create /// /// Parses the standard Facebook user JSON object for the properties. Note that picture /// has been added manually to be included in the user object /// </summary> /// <param name="jsonUser"></param> /// <returns></returns> /// public static FacebookUser Create(System.Web.Security.FormsIdentity identity, JObject jsonUser) { FacebookUser user = new FacebookUser(); user.identity = identity; if (jsonUser != null) { JToken value = null; if (jsonUser.TryGetValue("id", out value)) { user.id = jsonUser.SelectToken("id").Value <String>(); } if (jsonUser.TryGetValue("name", out value)) { user.name = jsonUser.SelectToken("name").Value <String>(); } if (jsonUser.TryGetValue("first_name", out value)) { user.first_name = jsonUser.SelectToken("first_name").Value <String>(); } if (jsonUser.TryGetValue("last_name", out value)) { user.last_name = jsonUser.SelectToken("last_name").Value <String>(); } if (jsonUser.TryGetValue("gender", out value)) { user.gender = jsonUser.SelectToken("gender").Value <String>(); } if (jsonUser.TryGetValue("link", out value)) { user.link = jsonUser.SelectToken("link").Value <String>(); } if (jsonUser.TryGetValue("about", out value)) { user.about = jsonUser.SelectToken("about").Value <String>(); } if (jsonUser.TryGetValue("bio", out value)) { user.bio = jsonUser.SelectToken("bio").Value <String>(); } if (jsonUser.TryGetValue("birthday", out value)) { user.birthday = jsonUser.SelectToken("birthday").Value <String>(); } if (jsonUser.TryGetValue("email", out value)) { user.email = jsonUser.SelectToken("email").Value <String>(); } if (jsonUser.TryGetValue("hometown", out value)) { user.hometown = jsonUser.SelectToken("hometown").Value <String>(); } if (jsonUser.TryGetValue("location", out value)) { user.location = jsonUser.SelectToken("location").Value <String>(); } if (jsonUser.TryGetValue("quotes", out value)) { user.quotes = jsonUser.SelectToken("quotes").Value <String>(); } if (jsonUser.TryGetValue("picture", out value)) { user.picture = jsonUser.SelectToken("picture").Value <String>(); } if (jsonUser.TryGetValue("significant_other", out value)) { user.significant_other = FacebookFriend.Create((JObject)jsonUser.SelectToken("significant_other")); } } return(user); }