public string GetAppName() { System.Web.Routing.RouteValueDictionary routeValues = HttpContext.Current.Request.RequestContext.RouteData.Values; string name = string.Empty; if (routeValues != null) { if (routeValues.ContainsKey("action")) { name += routeValues["action"].ToString(); } if (routeValues.ContainsKey("controller")) { name += routeValues["controller"].ToString(); } } if (name == string.Empty) { return("app"); } return(name.FirstCharToLower()); }
/// <summary> /// Получить имя текущего action /// </summary> /// <returns></returns> public static string getCurrentActionName() { System.Web.Routing.RouteValueDictionary routeValues = HttpContext.Current.Request.RequestContext.RouteData.Values; if (routeValues.ContainsKey("action")) { return((string)routeValues["action"]); } return(string.Empty); }
private static bool TryGetProtocol(RouteValueDictionary routeValues, out string protocol) { Ssl? ssl = null; if ((routeValues != null) && (routeValues.ContainsKey("controller"))) { ssl = RouteOptions.Current.GetOptionForValues(routeValues["controller"] as string); } protocol = ProtocolString(ssl); return ssl.HasValue; }
/// <summary> /// 分页Pager显示 /// </summary> /// <param name="html"></param> /// <param name="currentPageStr">标识当前页码的QueryStringKey</param> /// <param name="pageSize">每页显示</param> /// <param name="totalCount">总数据量</param> /// <returns></returns> public static MvcHtmlString Pager <T>(this HtmlHelper html, PageDTO <T> page) where T : PageModel, new() { var currentPageStr = "page"; var pageSize = page.Size.Value; var totalCount = page.RecordCount; var queryString = html.ViewContext.HttpContext.Request.QueryString; int currentPage = page.Page.Value; //当前页 var totalPages = page.PageCount; //总页数 var dict = new System.Web.Routing.RouteValueDictionary(html.ViewContext.RouteData.Values); var output = new StringBuilder(); if (!string.IsNullOrEmpty(queryString[currentPageStr])) { //与相应的QueryString绑定 foreach (string key in queryString.Keys) { if (queryString[key] != null && !string.IsNullOrEmpty(key)) { dict[key] = queryString[key]; } } int.TryParse(queryString[currentPageStr], out currentPage); } else { //获取 ~/Page/{page number} 的页号参数 if (dict.ContainsKey(currentPageStr)) { int.TryParse(dict[currentPageStr].ToString(), out currentPage); } } //保留查询字符到下一页 foreach (string key in queryString.Keys) { dict[key] = queryString[key]; } //如果有需要,保留表单值到下一页 (我暂时不需要, 所以注释掉) //var formValue = html.ViewContext.HttpContext.Request.Form; //foreach (string key in formValue.Keys) // if (formValue[key] != null && !string.IsNullOrEmpty(key)) // dict[key] = formValue[key]; if (currentPage <= 0) { currentPage = 1; } if (totalPages > 1) { output.AppendLine("<div class=\"row DTTTFooter\">"); output.AppendLine("<div class=\"col-sm-6\">"); var start = 0; start = (currentPage - 1) * pageSize + 1; var end = start + pageSize; if (end > totalCount) { end = totalCount; } output.AppendFormat("<div class=\"dataTables_info\">Showing {1} to {2} of {0} entries</div>", totalCount, start, end); output.AppendLine("</div>"); output.AppendLine("<div class=\"col-sm-6\"><div class=\"dataTables_paginate paging_bootstrap\" id=\"simpledatatable_paginate\"> <ul class=\"pagination\">"); //if (currentPage != 1) //{ // //处理首页连接 // dict[currentPageStr] = 1; // output.AppendFormat("{0} ", html.RouteLink("首页", dict)); //} if (currentPage > 1) { //处理上一页的连接 dict[currentPageStr] = currentPage - 1; output.Append("<li class=\"prev disabled\">"); output.Append(html.RouteLink("Prev", dict)); output.Append("</li>"); } else { output.Append("<li class=\"prev disabled\"><a href=\"javascript:;\">Prev</a></li>"); } int currint = 3; for (int i = 0; i <= 6; i++) { //一共最多显示10个页码,前面5个,后面5个 if ((currentPage + i - currint) >= 1 && (currentPage + i - currint) <= totalPages) { if (currint == i) { //当前页处理 output.AppendFormat(" <li class=\"active\"><a href=\"javascript:;\">{0}</a></li>", currentPage); } else { //一般页处理 dict[currentPageStr] = currentPage + i - currint; output.Append("<li>"); output.Append(html.RouteLink((currentPage + i - currint).ToString(), dict)); output.Append("</li>"); } } output.Append(" "); } if (currentPage < totalPages) { //处理下一页的链接 dict[currentPageStr] = currentPage + 1; output.Append("<li class=\"next\">"); output.Append(html.RouteLink("Next", dict)); output.Append("</li>"); } else { output.Append("<li class=\"next disabled\"><a href=\"javascript:;\">Next</a></li>"); } output.Append("</ul></div></div></div>"); } // output.AppendFormat("{0} / {1}", currentPage, totalPages);//这个统计加不加都行 return(new MvcHtmlString(output.ToString())); }
protected override void OnActionExecuting(ActionExecutingContext filterContext) { var referrer = Request.UrlReferrer; if (Request.RawUrl.ToLower().Contains("partial") && referrer != null) { if (referrer.ToString().ToLower().Contains("login")) { filterContext.Result = RedirectToAction("Index", "Home"); base.OnActionExecuting(filterContext); return; } } else if (Request.RawUrl.ToLower().Contains("partial") && referrer == null) { filterContext.Result = RedirectToAction("Index", "Home"); base.OnActionExecuting(filterContext); return; } var LanguageData = PageLanguageHelper.GetLanguageContent("User", "Base/OnActionExecuting"); //Check authentification and user role var currentUser = SessionManager.GetUserSession(); //new check if end user and get user created User currentUserCreated = null; if (currentUser != null && currentUser.IsEndUser()) { var currentCustomer = Upsilab.Business.Utility.SessionManager.GetCustomerProspectSession(); currentUserCreated = currentCustomer.User1; } //end new Authentication authentification = Authentication.Parse(filterContext.ActionDescriptor.GetCustomAttributes(typeof(Authentication), false).FirstOrDefault()); if (authentification != null) { if (currentUser != null) { //TODO : checking user role using Feature object from database if (!authentification.HasAccess(currentUser, currentUserCreated)) { UserBL.Logout(); //Logout ? trying to access denied url, then logout ? filterContext.Result = RedirectToAction("ForceLogin", "User", new { isAjax = authentification.IsAjax }); return; } } else { string tempDataKey = Upsilab.Web.ExtranetUser.Controllers.UserController.LoginPageParameters.ReturnUrl; if (!TempData.ContainsKey(tempDataKey)) { TempData.Add(tempDataKey, Request.RawUrl); } if (Request.QueryString.Keys.Count > 0) { var redirect = new System.Web.Routing.RouteValueDictionary(); foreach (String key in Request.QueryString.Keys) { if (!redirect.ContainsKey(key)) { redirect.Add(key, Request.QueryString[key]); } } filterContext.Result = RedirectToAction("Login", "User", redirect); return; } filterContext.Result = RedirectToAction("ForceLogin", "User", new { isAjax = authentification.IsAjax }); return; } } //Set default language if (SessionManager.GetCurrentLanguage() == null) { SessionManager.SetCurrentLanguage(LanguageTypeBL.GetLanguageTypeByLanguageName(LanguageTypeBL.LanguageTypes.French)); } //Set application name if (currentUser != null) { string currentApplication = SessionManager.GetApplicationNameSession(); if (string.IsNullOrEmpty(currentApplication) && !currentUser.IsEndUser()) { currentApplication = Upsilab.Business.Souscription.SouscriptionBL.ReportLabApplication; //By default if (currentUser.IsSdgAdmin()) { currentApplication = Upsilab.Business.Souscription.SouscriptionBL.SignatureApplication; } else if (!Request.RawUrl.ToLower().Contains("/agreg") && (currentUser.HasReportLicense() || currentUser.HasLABLicense())) { currentApplication = Upsilab.Business.Souscription.SouscriptionBL.ReportLabApplication; } else if (Request.RawUrl.ToLower().Contains("/agreg") && currentUser.HasAggregatorLicense()) { currentApplication = Upsilab.Business.Souscription.SouscriptionBL.AgregateurApplication; } else if (currentUser.HasReportLicense() || currentUser.HasLABLicense()) { currentApplication = Upsilab.Business.Souscription.SouscriptionBL.ReportLabApplication; } else if (currentUser.HasAggregatorLicense()) { currentApplication = Upsilab.Business.Souscription.SouscriptionBL.AgregateurApplication; } SessionManager.SetApplicationNameSession(currentApplication); } } //4993 : Check IP address. Send mail to [email protected] if it's an competitor IP Upsilab.Business.Utility.SecurityHelper.CheckcompetitorIP(); base.OnActionExecuting(filterContext); }