private void ReUrl_BeginRequest(object sender, EventArgs e) { HttpContext context = ((HttpApplication)sender).Context; //��ֹ����ҳ�滺�� context.Response.Buffer = true; context.Response.ExpiresAbsolute = System.DateTime.Now.AddSeconds(-1); context.Response.Expires = 0; context.Response.CacheControl = "no-cache"; string text = "/"; string input = context.Request.Path.ToLower(); string ip = XYECOM.Core.XYRequest.GetIP(); //IP�ж� if (XYECOM.Configuration.Security.Instance._ForbidIP.Contains(ip)) { context.Response.Write("-��ֹ����-"); context.Response.End(); } //��̨�����ļ���·�� string adminDir = XYECOM.Configuration.WebInfo.Instance.AdminFolder.ToLower(); //����ǹ���Ŀ¼����֤���ļ���ֱ�ӽ��� if (input.StartsWith(text + adminDir + "/")) { return; } //�������֤���ļ���ֱ�ӽ��� if (input.StartsWith(text + "common/validatecode.ashx")) { return; } //�����ͨ��Ŀ¼��ֱ�ӽ��� if (input.StartsWith(text + "common/")) { return; } //ϵͳ�Ƿ�������״̬ if (!XYECOM.Configuration.WebInfo.Instance.IsRun) { context.Response.Write(XYECOM.Configuration.WebInfo.Instance.SiteCloseTip); context.Response.End(); } //�����ע����½ֱ�ӽ��� if (input.StartsWith("/login.aspx") || input.StartsWith("/register.aspx") || input.StartsWith("/getpassword.aspx")) { return; } if (input.EndsWith(".js") || input.EndsWith(".png") || input.EndsWith(".jpeg") || input.EndsWith(".jpg") || input.EndsWith(".bmp") || input.EndsWith(".css") || input.EndsWith(".gif")) { return; } string curDomain = context.Request.Url.Authority; bool isTopDomain = true; if (curDomain.StartsWith("192.168") || curDomain.StartsWith("127.0") || curDomain.StartsWith("localhost")) { isTopDomain = false; } ///�û������������� if (isTopDomain && IsUserTopDomain(curDomain)) { Model.UserDomainInfo udInfo = userDomainBLL.GetItem(curDomain); if (udInfo == null || udInfo.State != XYECOM.Model.AuditingState.Passed) { context.Response.Status = "301 Moved Permanently"; context.Response.AddHeader("Location", webInfo.WebDomain); context.Response.End(); return; } string userTmpName = string.Empty; XYECOM.Model.UserRegInfo userRegInfo = userRegBLL.GetItem(udInfo.UserId); if (userRegInfo != null) { if (Business.UserGradePopedom.IsBindingTopdomain(userRegInfo.GradeId)) { userTmpName = userRegInfo.TemplateName; if (userTmpName.IndexOf("|") != -1) { userTmpName = userTmpName.Split('|')[0]; } } } if (string.IsNullOrEmpty(userTmpName)) { context.Response.Status = "301 Moved Permanently"; context.Response.AddHeader("Location", webInfo.WebDomain); context.Response.End(); return; } foreach (URLPatternInfo rewrite2 in Urls.Instance.TopShopUrlItems) { string tmpInput = input == "/" ? "/index." + webInfo.WebSuffix : input; if (Regex.IsMatch(context.Request.Url.Host + tmpInput, rewrite2.Pattern, RegexOptions.Compiled | RegexOptions.IgnoreCase)) { string queryString = Regex.Replace(context.Request.Url.Host + tmpInput, rewrite2.Pattern, rewrite2.QueryString, RegexOptions.Compiled | RegexOptions.IgnoreCase); context.RewritePath(text + "aspx/" + rewrite2.Page.Insert(rewrite2.Page.LastIndexOf("/"), userTmpName), string.Empty, queryString); return; } } } if (input.StartsWith(text)) { //��ǰģ������ string curTmpName = XYECOM.Configuration.Template.Instance.Path; //�Ƿ����ö������� bool isDomain = XYECOM.Configuration.WebInfo.Instance.IsDomain; //�Ƿ����õ����������� bool isAreaDomain = XYECOM.Configuration.WebInfo.Instance.IsAreaDomain; string urlPrefix = GetURLPrefix(context.Request.Url.Host); if (input == text) { context.RewritePath("/aspx/" + curTmpName + "/index." + webInfo.WebSuffix); return; } //�������Ϊ�������� if (!urlPrefix.Equals("")) { //����Ѿ����õ����������� if (isAreaDomain) { string customAreaFolder = ""; Model.AreaSiteInfo areaSiteInfo = new Business.AreaSite().GetItemByFlagName(urlPrefix); if (areaSiteInfo != null) { if (areaSiteInfo.IsCostomTemplate) customAreaFolder = urlPrefix; foreach (URLPatternInfo rewrite2 in Urls.Instance.AreaUrlItems) { if (Regex.IsMatch(context.Request.Url.Host + input, rewrite2.Pattern, RegexOptions.Compiled | RegexOptions.IgnoreCase)) { string queryString = Regex.Replace(context.Request.Url.Host + input, rewrite2.Pattern, rewrite2.QueryString, RegexOptions.Compiled | RegexOptions.IgnoreCase); context.RewritePath(text + "aspx/" + curTmpName + rewrite2.Page.Insert(rewrite2.Page.LastIndexOf("/"), customAreaFolder), string.Empty, queryString); return; } } } } //������������ö������� if (isDomain) { string userTmpName = ""; if (context.Request.Url.Host.Contains("localhost") || context.Request.Url.Host.Contains("127.0.0.1")) { userTmpName = "default"; } else { XYECOM.Model.UserRegInfo userRegInfo = userRegBLL.GetItem(urlPrefix); if (userRegInfo != null) { if (Business.UserGradePopedom.IsSubdomain(userRegInfo.GradeId)) { userTmpName = userRegInfo.TemplateName; if (userTmpName.IndexOf("|") != -1) userTmpName = userTmpName.Split('|')[0]; } } } if (userTmpName != "") { foreach (URLPatternInfo rewrite2 in Urls.Instance.ShopUrlItems) { if (Regex.IsMatch(context.Request.Url.Host + input, rewrite2.Pattern, RegexOptions.Compiled | RegexOptions.IgnoreCase)) { string queryString = Regex.Replace(context.Request.Url.Host + input, rewrite2.Pattern, rewrite2.QueryString, RegexOptions.Compiled | RegexOptions.IgnoreCase); context.RewritePath(text + "aspx/" + rewrite2.Page.Insert(rewrite2.Page.LastIndexOf("/"), userTmpName), string.Empty, queryString); return; } } } } } if (input.Substring(text.Length).IndexOf("/") == -1) { context.RewritePath(text + "aspx/" + curTmpName + input.Substring(context.Request.Path.LastIndexOf("/"))); return; } if (input.StartsWith(text + "upload/")) { context.RewritePath(input.Substring(7)); return; } //��Ʒ��Ŀ�����Ȳ鿴�Ƿ�Ϊ�Զ����ļ�����Ŀ if (input.StartsWith(text + "cate/")) { foreach (URLPatternInfo rewrite2 in Urls.Instance.ProCateUrlItems) { if (Regex.IsMatch(context.Request.Url.Host + input, rewrite2.Pattern, RegexOptions.Compiled | RegexOptions.IgnoreCase)) { int startIndex = 6; int endIndex = input.LastIndexOf("-"); int length = endIndex - startIndex; string proFlagName = input.Substring(startIndex, length); Model.ProductTypeInfo proTypeInfo = new Business.ProductType().GetItemByFlagName(proFlagName); string customFolder = ""; if (proTypeInfo != null && proTypeInfo.IsCustomTemplate) { customFolder = proFlagName; } string queryString = Regex.Replace(input, rewrite2.Pattern, rewrite2.QueryString, RegexOptions.Compiled | RegexOptions.IgnoreCase); context.RewritePath(text + "aspx/" + curTmpName + rewrite2.Page.Insert(rewrite2.Page.LastIndexOf("/"), customFolder), string.Empty, queryString); return; } } } if (input.StartsWith(text + "shop/")) { string userName = ""; if (context.Request.QueryString["u_name"] != null) userName = context.Request.QueryString["u_name"].ToString(); else userName = input.Substring(6, input.LastIndexOf("/") - 6); XYECOM.Model.UserRegInfo userRegInfo = userRegBLL.GetItem(userName); string userTmpName = "default"; if (userRegInfo != null) { userTmpName = userRegInfo.TemplateName; if (userTmpName.IndexOf("|") != -1) userTmpName = userTmpName.Split('|')[0]; } foreach (URLPatternInfo rewrite2 in Urls.Instance.SpUrlItems) { if (Regex.IsMatch(input, rewrite2.Pattern, RegexOptions.Compiled | RegexOptions.IgnoreCase)) { string queryString = Regex.Replace(input, rewrite2.Pattern, rewrite2.QueryString, RegexOptions.Compiled | RegexOptions.IgnoreCase); context.RewritePath(text + "aspx/" + rewrite2.Page.Insert(rewrite2.Page.LastIndexOf("/"), userTmpName), string.Empty, queryString); return; } } return; } //ȫ��ƥ�� foreach (URLPatternInfo rewrite2 in Urls.Instance.GeneralUrlItems) { if (Regex.IsMatch(input, rewrite2.Pattern, RegexOptions.Compiled | RegexOptions.IgnoreCase)) { string queryString = Regex.Replace(input, rewrite2.Pattern, rewrite2.QueryString, RegexOptions.Compiled | RegexOptions.IgnoreCase); context.RewritePath(text + "aspx/" + curTmpName + rewrite2.Page, string.Empty, queryString); return; } } string folderName = ""; if (input.StartsWith(text + "area/")) folderName = "area"; if (input.StartsWith(text + "cate/")) folderName = "cate"; if (input.StartsWith(text + "search/")) folderName = "search"; if (input.StartsWith(text + "creditor/")) folderName = "creditor"; if (input.StartsWith(text + "server/")) folderName = "server"; if (!string.IsNullOrEmpty(folderName)) { string vPath = text + "aspx/" + curTmpName + "/" + folderName + "/" + input.Substring(context.Request.Path.LastIndexOf("/")); if (folderName == "creditor" || folderName == "server") { string filePath = context.Server.MapPath(vPath); if (!System.IO.File.Exists(filePath)) { return; } } context.RewritePath(vPath); return; } string text1 = input.Substring(text.Length, input.LastIndexOf('/') - 1); foreach (XYECOM.Configuration.ModuleInfo item in XYECOM.Configuration.Module.Instance.ModuleItems) { if (Regex.IsMatch(text1, item.EName, RegexOptions.Compiled | RegexOptions.IgnoreCase)) { context.RewritePath(text + "aspx/" + curTmpName + "/" + item.EName + "/" + input.Substring(context.Request.Path.LastIndexOf("/"))); return; } } context.RewritePath(text + "aspx/" + curTmpName + input.Substring(context.Request.Path.LastIndexOf("/"))); //add by botao 2010-04-21 context.Response.Flush(); } }
/// <summary> /// ��ȡ���ս�� /// </summary> /// <returns></returns> public override string CreateHTML() { string pageSuffix = config.WebSuffix; //�������̣��ӹ�������Ʒ�ƣ���ҵ string linkUrl = config.WebDomain+ "search/seller_search." + pageSuffix + "?flag={0}&typeid={1}&usertypeid={2}&areaid={3}"; string bogueStaticLinkUrl = config.WebDomain + "search/seller_search-{0}-{1}--{2}--{3}----." + pageSuffix; string buylinkUrl = config.WebDomain + "search/buyer_search." + pageSuffix + "?flag={0}&typeid={1}&usertypeid={2}&areaid={3}"; string bogueStaticBuyLinkUrl = config.WebDomain + "search/buyer_search-{0}-{1}--{2}--{3}----." + pageSuffix; //ְλ string jobLinkUrl = config.WebDomain + "job/list." + pageSuffix + "?typeid={0}"; string bogusStaticJobLinkUrl = config.WebDomain + "job/list-{0}-------." + pageSuffix; //������Ѷ���� string newsSearchUrl = config.WebDomain + "search/news_search." + pageSuffix + "?typeid={0}"; string bogueStaticNewsSearchUrl = config.WebDomain + "search/news_search--{0}------." + pageSuffix; //����Ƶ���б� string newsLinkUrl = config.WebDomain + "news/{0}channel." + pageSuffix + "?nt_id={1}"; string bogusStaticNewsLinkUrl = config.WebDomain + "news/{0}channel-{1}." + pageSuffix; //�ٿ� string baikeLinkUrl = "/baike/list." + pageSuffix + "?typeid={0}"; string bogusStaticbaikeLinkUrl = "/baike/list-{0}--." + pageSuffix; //�������� //�������̣��ӹ�������Ʒ�ƣ���ҵ string areasellLinkUrl = config.WebDomain + "search/seller_search." + pageSuffix + "?flag={1}&areaid={0}"; string areasellBogueStaticLinkUrl = config.WebDomain + "search/seller_search-{1}-----{0}----." + pageSuffix + ""; string areabuyLinkUrl = config.WebDomain + "search/buyer_search." + pageSuffix + "?flag={1}&areaid={0}"; string areabuyBogueStaticLinkUrl = config.WebDomain + "search/buyer_search-{1}-----{0}----." + pageSuffix + ""; //����������ְλ��Ϣ���� string areajobLinkUrl = config.WebDomain + "job/list." + pageSuffix + "?areaid={0}"; string areabogusStaticJobLinkUrl = config.WebDomain + "job/list--{0}------." + pageSuffix + ""; //+++++++++++++ pro cate ++++++++++++++++++++++++++++ string cateUrl = config.WebDomain + "cate/index." + pageSuffix + "?fn={0}"; string bogueStaticCateUrl = config.WebDomain + "cate/{0}-index." + pageSuffix; string domainCateUrl = "http://{0}" + config.GetShortDomain(); string _CateUrl = cateUrl; if (config.IsProTypeDomain) _CateUrl = domainCateUrl; else if (config.IsBogusStatic) _CateUrl = bogueStaticCateUrl; Regex cateLinkRegx = new Regex(@"\[cate-link:(([a-zA-Z]+)\,(\d+))\]"); //++++++++++++++++++++++++++++++++++++++++++++++++++++ Business.ClassLabel BLL = new XYECOM.Business.ClassLabel(); Model.ClassLabelInfo clsLabelInfo = BLL.GetItem(labelName); if (clsLabelInfo == null) throw new XYECOM.Core.LabelException("��ǩ��������ǩ�����ڻ��ѱ�ɾ����"); string labelBody = clsLabelInfo.Body; Regex jobLinkRegx = new Regex(@"\[job-link:(\d+)\]"); Regex linkRegx = new Regex(@"\[link:(([a-zA-Z]+)\,(\d+))\]"); Regex buylinkRegx = new Regex(@"\[buy-link:(([a-zA-Z]+)\,(\d+))\]"); Regex newsLinkRegx = new Regex(@"\[news-link:(\d+)\]"); Regex baikeLinkRegx = new Regex(@"\[baike-link:(\d+)\]"); //add by liujia 2008-11-18 ������ַ���� Regex areajob = new Regex(@"\[area-job:(\d+)\]"); Regex areasell = new Regex(@"\[area-sell:(\d+),(\w+)\]"); Regex areabuy = new Regex(@"\[area-buy:(\d+),(\w+)\]"); //Add by tc 2009-5-20 �ط�վ������ǩ���� Regex asn = new Regex(@"\[ASN:(\d+)\]"); string asnLinkUrl = config.WebDomain + "area/index." + pageSuffix + "?fn={0}"; string bogusStaticASNLinkUrl = config.WebDomain + "area/{0}-index." + pageSuffix + ""; string dASNLinkUrl = config.GetSubDomain("{0}"); //add by tc 2009-05-31 Regex tsn = new Regex(@"\[TSN:(\d+)\]"); string tsnLinkUrl = config.WebDomain + "trade/index." + pageSuffix + "?fn={0}"; string bogusStaticTSNLinkUrl = config.WebDomain + "trade/{0}-index." + pageSuffix + ""; string dTSNLinkUrl = config.GetSubDomain("{0}"); string userTypeIdStr = ""; string areaIdStr = ""; foreach (Match m in linkRegx.Matches(labelBody)) { if (XYECOM.Configuration.WebInfo.Instance.IsBogusStatic) { if (m.Groups[2].ToString().Equals("news")) { labelBody = labelBody.Replace(m.Groups[0].ToString(), string.Format(bogueStaticNewsSearchUrl, m.Groups[3].ToString(),userTypeIdStr,areaIdStr)); } else { userTypeIdStr = GetUserTypeIdStr(m.Groups[2].ToString()); areaIdStr = GetAreaIdStr(); labelBody = labelBody.Replace(m.Groups[0].ToString(), string.Format(bogueStaticLinkUrl, m.Groups[2].ToString(), m.Groups[3].ToString(),userTypeIdStr,areaIdStr)); } } else { if (m.Groups[2].ToString().Equals("news")) { labelBody = labelBody.Replace(m.Groups[0].ToString(), string.Format(newsSearchUrl, m.Groups[3].ToString(),userTypeIdStr,areaIdStr)); } else { userTypeIdStr = GetUserTypeIdStr(m.Groups[2].ToString()); areaIdStr = GetAreaIdStr(); labelBody = labelBody.Replace(m.Groups[0].ToString(), string.Format(linkUrl, m.Groups[2].ToString(), m.Groups[3].ToString(),userTypeIdStr,areaIdStr)); } } } foreach (Match m in buylinkRegx.Matches(labelBody)) { userTypeIdStr = GetUserTypeIdStr(m.Groups[2].ToString()); areaIdStr = GetAreaIdStr(); if (XYECOM.Configuration.WebInfo.Instance.IsBogusStatic) { labelBody = labelBody.Replace(m.Groups[0].ToString(), string.Format(bogueStaticBuyLinkUrl, m.Groups[2].ToString(), m.Groups[3].ToString(),userTypeIdStr,areaIdStr)); } else { labelBody = labelBody.Replace(m.Groups[0].ToString(), string.Format(buylinkUrl, m.Groups[2].ToString(), m.Groups[3].ToString(),userTypeIdStr,areaIdStr)); } } //Prodcut Cate string proFlagName = ""; foreach (Match m in cateLinkRegx.Matches(labelBody)) { long proTypeId = Core.MyConvert.GetInt64(m.Groups[3].ToString()); if (proTypeId <= 0) { labelBody = labelBody.Replace(m.Groups[0].ToString(), "#"); continue; } Model.ProductTypeInfo ptInfo = new Business.ProductType().GetItem(proTypeId); if (ptInfo == null) { labelBody = labelBody.Replace(m.Groups[0].ToString(), "#"); continue; } proFlagName = ptInfo.FlagName.Trim(); if (!proFlagName.Equals("")) { labelBody = labelBody.Replace(m.Groups[0].ToString(), string.Format(_CateUrl, proFlagName)); continue; } userTypeIdStr = GetUserTypeIdStr(m.Groups[2].ToString()); areaIdStr = GetAreaIdStr(); if (XYECOM.Configuration.WebInfo.Instance.IsBogusStatic) { labelBody = labelBody.Replace(m.Groups[0].ToString(), string.Format(bogueStaticLinkUrl, m.Groups[2].ToString(), m.Groups[3].ToString(), userTypeIdStr, areaIdStr)); } else { labelBody = labelBody.Replace(m.Groups[0].ToString(), string.Format(linkUrl, m.Groups[2].ToString(), m.Groups[3].ToString(), userTypeIdStr, areaIdStr)); } } foreach (Match m in jobLinkRegx.Matches(labelBody)) { if (XYECOM.Configuration.WebInfo.Instance.IsBogusStatic) labelBody = labelBody.Replace(m.Groups[0].ToString(), string.Format(bogusStaticJobLinkUrl, m.Groups[1].ToString())); else labelBody = labelBody.Replace(m.Groups[0].ToString(), string.Format(jobLinkUrl, m.Groups[1].ToString())); } foreach (Match m in newsLinkRegx.Matches(labelBody)) { int _NTID = XYECOM.Core.MyConvert.GetInt32(m.Groups[1].ToString()); bool isHTML = false; string subChannelFolder = ""; if (_NTID > 0) { Model.NewsTitlesInfo channel = new Business.NewsTitles().GetItem(_NTID); if (channel != null) { //����Ѿ����ɾ�̬ҳ���ؾ�̬ҳ���ַ if (channel.HTMLPage != string.Empty && channel.HTMLPage != "") { isHTML = true; labelBody = labelBody.Replace(m.Groups[0].ToString(), XYECOM.Configuration.WebInfo.Instance.WebDomain + channel.HTMLPage); } subChannelFolder = channel.TempletFolderAddress.Trim(); if (!subChannelFolder.Equals("")) subChannelFolder = subChannelFolder + "/"; } } if (!isHTML) { if (XYECOM.Configuration.WebInfo.Instance.IsBogusStatic) labelBody = labelBody.Replace(m.Groups[0].ToString(), string.Format(bogusStaticNewsLinkUrl, subChannelFolder,m.Groups[1].ToString())); else labelBody = labelBody.Replace(m.Groups[0].ToString(), string.Format(newsLinkUrl, subChannelFolder,m.Groups[1].ToString())); } } //add by liujia 2008-11-18 ������ַ���� foreach (Match m in areajob.Matches(labelBody)) { if (XYECOM.Configuration.WebInfo.Instance.IsBogusStatic) labelBody = labelBody.Replace(m.Groups[0].ToString(), string.Format(areabogusStaticJobLinkUrl, m.Groups[1].ToString())); else labelBody = labelBody.Replace(m.Groups[0].ToString(), string.Format(areajobLinkUrl, m.Groups[1].ToString())); } //�ٿ� foreach (Match m in baikeLinkRegx.Matches(labelBody)) { if (XYECOM.Configuration.WebInfo.Instance.IsBogusStatic) labelBody = labelBody.Replace(m.Groups[0].ToString(), string.Format(bogusStaticbaikeLinkUrl, m.Groups[1].ToString())); else labelBody = labelBody.Replace(m.Groups[0].ToString(), string.Format(baikeLinkUrl, m.Groups[1].ToString())); } foreach (Match m in areasell.Matches(labelBody)) { if (XYECOM.Configuration.WebInfo.Instance.IsBogusStatic) labelBody = labelBody.Replace(m.Groups[0].ToString(), string.Format(areasellBogueStaticLinkUrl, m.Groups[1].ToString(), m.Groups[2].ToString())); else labelBody = labelBody.Replace(m.Groups[0].ToString(), string.Format(areasellLinkUrl, m.Groups[1].ToString(), m.Groups[2].ToString())); } foreach (Match m in areabuy.Matches(labelBody)) { if (XYECOM.Configuration.WebInfo.Instance.IsBogusStatic) labelBody = labelBody.Replace(m.Groups[0].ToString(), string.Format(areabuyBogueStaticLinkUrl, m.Groups[1].ToString(), m.Groups[2].ToString())); else labelBody = labelBody.Replace(m.Groups[0].ToString(), string.Format(areabuyLinkUrl, m.Groups[1].ToString(), m.Groups[2].ToString())); } foreach (Match m in asn.Matches(labelBody)) { int sId = Core.MyConvert.GetInt32(m.Groups[1].ToString()); string flagName = new Business.AreaSite().GetItemBySiteId(sId).FlagName; if (XYECOM.Configuration.WebInfo.Instance.IsAreaDomain) { labelBody = labelBody.Replace(m.Groups[0].ToString(), string.Format(dASNLinkUrl, flagName)); } else { if (XYECOM.Configuration.WebInfo.Instance.IsBogusStatic) labelBody = labelBody.Replace(m.Groups[0].ToString(), string.Format(bogusStaticASNLinkUrl, flagName)); else labelBody = labelBody.Replace(m.Groups[0].ToString(), string.Format(asnLinkUrl, flagName)); } } return labelBody; }