子公司集成集团单点登录修改内容

This commit is contained in:
geh
2025-11-13 17:32:14 +08:00
parent 0defba7f03
commit feb517dd8d
3 changed files with 200 additions and 22 deletions
+72 -22
View File
@@ -131,37 +131,87 @@ namespace FineUIPro.Web
protected override void OnInit(EventArgs e)
{
string url = HttpContext.Current.Request.Path;
string a = Request.ServerVariables["HTTP_REFERER"];
string Referer = Request.Headers["Referer"];
if (a==null)
string fullPath = HttpContext.Current.Request.Path;
string appPath = HttpContext.Current.Request.ApplicationPath; // 获取应用程序根路径
// 确保应用程序路径以 "/" 开头并移除它
if (!string.IsNullOrEmpty(appPath) && fullPath.StartsWith(appPath, StringComparison.OrdinalIgnoreCase))
{
bool IsDataShowPage = ConstValue.drpConstItemList(ConstValue.Group_InterfacePopup).FirstOrDefault(x => url.Contains(x.ConstValue)) != null;
bool IsSafeReferer = ConstValue.drpConstItemList(ConstValue.Group_SafeReferer).FirstOrDefault(x => x.ConstValue == url) != null;
if (!IsDataShowPage && !IsSafeReferer)
{
if (this.Page.Request.AppRelativeCurrentExecutionFilePath != "~/Login.aspx")
Response.Redirect("~/Login.aspx");
return;
}
fullPath = fullPath.Substring(appPath.Length); // 去掉应用程序根路径
}
else
//去除fullPath 开头的 /
if (fullPath.StartsWith("/"))
{
Uri uri = new Uri(a);
Uri uri2 = new Uri(SysConstSetService.CNCECPath);
if (uri.Host==uri2.Host)
fullPath = fullPath.Remove(0, 1);
}
// 检查auth_token参数实现iframe自动登录
string authToken = Request.QueryString["auth_token"];
if (!string.IsNullOrEmpty(authToken) && this.CurrUser == null)
{
try
{
if (this.CurrUser == null)
// 解密并验证token
string decryptedToken = BLL.TokenHelper.DecryptToken(authToken);
var tokenData = JsonConvert.DeserializeObject<dynamic>(decryptedToken);
// 验证时间戳(2小时有效期)
long timestamp = tokenData.timestamp;
if (DateTimeOffset.Now.ToUnixTimeSeconds() - timestamp <= 7200) // 2小时 = 7200秒
{
this.Session["CurrUser"] = UserService.GetUserByUserId(Const.sysglyId);
// 验证用户ID
string userId = tokenData.user_id;
if (userId == Const.sysglyId)
{
var user = UserService.GetUserByUserId(Const.sysglyId);
if (user != null)
{
this.Session["CurrUser"] = user;
BLL.LogService.AddLog(Const.sysglyId, "iframe Token自动登录成功");
}
}
}
}
catch (Exception ex)
{
BLL.LogService.AddLog("", $"iframe Token自动登录失败:{ex.Message}");
}
}
string httpRefere = Request.ServerVariables["HTTP_REFERER"];
if (httpRefere==null) //判断是否为空。目的是为了防止直接在浏览器地址栏输入网址访问
{
bool IsDataShowPage = ConstValue.drpConstItemList(ConstValue.Group_InterfacePopup).FirstOrDefault(x => fullPath.Contains(x.ConstValue)) != null;
bool IsSafeReferer = ConstValue.drpConstItemList(ConstValue.Group_SafeReferer).FirstOrDefault(x => x.ConstValue == fullPath) != null;
// 如果不在安全页面列表中且用户未登录,重定向到登录页面
if (!IsDataShowPage && !IsSafeReferer && this.CurrUser == null)
{
string loginform = ConfigurationManager.AppSettings["LoginForm"];
if (!string.IsNullOrEmpty(loginform))
{
if (this.Page.Request.AppRelativeCurrentExecutionFilePath != "~/Login_ZJ.aspx")
Response.Redirect("~/Login_ZJ.aspx");
return;
}
}
}
/*if (CurrUser == null && HttpContext.Current.Request.Path != FormsAuthentication.LoginUrl)//防止没有登录直接访问通用界面
{
Response.Redirect(FormsAuthentication.LoginUrl);
}*/
//var menuModel = (from x in Funs.DB.Sys_Menu where x.Url.Contains(fullPath) select x.MenuId).ToList();//判断访问的页面是否在菜单中
//if (menuModel!=null&&menuModel.Count>0)
//{
// var thisUserAllMenuIdLis = CommonService.GetAllMenuList(this.CurrUser.LoginProjectId, this.CurrUser.UserId);
// if (menuModel.Intersect(thisUserAllMenuIdLis).Count()==0)
// {
// Response.Redirect(FormsAuthentication.LoginUrl);
// }
//}//没有在菜单中则不做权限判断(暂时没有控制弹窗的统一权限校验)
var pm = PageManager.Instance;
if (pm != null)
{
@@ -264,7 +314,7 @@ namespace FineUIPro.Web
System.Web.UI.HtmlControls.HtmlGenericControl linkCtrl = new System.Web.UI.HtmlControls.HtmlGenericControl("link");
linkCtrl.Attributes["rel"] = "stylesheet";
linkCtrl.Attributes["type"] = "text/css";
linkCtrl.Attributes["href"] = ResolveClientUrl("~/res/css/common.css?v" + GlobalConfig.ProductVersion);
/*linkCtrl.Attributes["href"] = ResolveClientUrl("~/res/css/common.css?v" + GlobalConfig.ProductVersion);*/
Header.Controls.AddAt(GetHeadStyleCSSIndex(), linkCtrl);