private void Page_Load(object sender, System.EventArgs e) { currentNode = (Node)Context.Items["currentNode"]; lang = SFGlobal.CurrentCulture.Name; rank = SFGlobal.IsNumeric(Page.CustomQueryString["page"]) ? int.Parse(Page.CustomQueryString["page"]) : 1; string sql = ""; string columns = "TOP 1 templateID, title, summary, keywords, body, dateModified "; if (SFGlobal.IsUserCMS()) { sql = "SELECT " + columns + " FROM " + dbTable + " WHERE nodeID={0} AND lang='{1}' AND rank = {2} ORDER BY preview DESC, publish DESC, dateModified DESC, version DESC"; } else { dbTable += SFGlobal.PublicSuffix; sql = "SELECT " + columns + " FROM " + dbTable + " WHERE nodeID = {0}AND lang = '{1}' and rank = {2}"; } sql = String.Format(sql, currentNode.Id, lang, rank); DataRow dr = SFGlobal.DAL.execDataRow(sql); if (dr != null) { article = loadArticle((int)dr["templateID"]); article.ArticleTitle = dr["title"].ToString(); article.ArticleBody = dr["body"].ToString(); article.Keywords = dr["keywords"].ToString(); article.Summary = dr["summary"].ToString(); article.LastModified = (DateTime)dr["dateModified"]; } else { article = loadArticle(1); article.ArticleBody = String.Format("<h2>Article not Found.</h2><p>There is no Article for this node yet. Publish a new article</p>"); article.ArticleTitle = "Error!"; article.Keywords = "ERROR"; article.Summary = "ERROR"; article.LastModified = DateTime.Now; //throw new DuryTools.ErrorHandler("Problem loading article. Possible causes: haven't published yet, no article for this language"); } holder.Controls.Add(article); }
// url scheme: http://mysite.com/en-CA/default.aspx // http://mysite.com/en-CA/whoweare/default.aspx // http://mysite.com/whoweare/gallery.aspx (uses default language) private void Application_BeginRequest(object sender, System.EventArgs e) { HttpApplication app = ((HttpApplication)(sender)); HttpContext context = app.Context; startTime = DateTime.Now; string r = context.Request.RawUrl; string virtualDir = (System.Configuration.ConfigurationSettings.AppSettings["virtualDirName"] != null) ? System.Configuration.ConfigurationSettings.AppSettings["virtualDirName"] : ""; string virtualFileExtension = (System.Configuration.ConfigurationSettings.AppSettings["virtualFileExtension"] != null) ? System.Configuration.ConfigurationSettings.AppSettings["virtualFileExtension"] : ".aspx"; RewriteConfigSettings cs = RewriteConfigSettings.GetSettings(); RequestConfigSettings rqcs = RequestConfigSettings.GetSettings(); // apply exceptions if (!cs.IsExcluded(r) && r.IndexOf(rqcs.AdminDirectory) < 0) { if (r[r.Length - 1] != '/' && virtualFileExtension == "" && r.IndexOf("?") == -1) { context.Response.Redirect(r + "/", true); } // lets cut the incoming url into the parts we're interested in string u = r.Substring(1); //context.Response.Write("1u=" + u + "<BR>"); //context.Response.Write("1r=" + r + "<BR>"); if (u.IndexOf("?") > 0) { u = u.Substring(0, u.IndexOf("?")); } if (virtualDir.Length > 0) { u = u.Replace(virtualDir, ""); } if (u.IndexOf(".aspx") > 0 && virtualDir.Length == 0) { u.Replace(".aspx", ""); } if (u != "" && virtualFileExtension != "" && virtualFileExtension.Length > 0) { try { u = u.Substring(0, u.IndexOf(virtualFileExtension)); //u.Replace(virtualFileExtension,""); } catch (Exception ex) { throw new Exception("substring 3 - " + u + ", " + r, ex); } } // split it! System.Collections.Specialized.StringCollection url_parts = new System.Collections.Specialized.StringCollection(); url_parts.AddRange(u.Split('/')); // find language identitfier -- if not found then set default System.Text.RegularExpressions.Regex regex = new System.Text.RegularExpressions.Regex("/[a-z]{2}-[a-zA-Z]{2}/|/[a-z]{2}/"); if (regex.IsMatch(r) && regex.Match(r).Index == 0) { setCulture(url_parts[0]); url_parts.RemoveAt(0); } else { setCulture(SFGlobal.DefaultLanguage); } // create pseudo-querystring string output = ""; foreach (string s in url_parts) { if (s.Length > 0 && !SFGlobal.IsNumeric(s)) { output += s + "*"; } } output = (output.Length > 1) ? output.Substring(0, output.Length - 1) : "default"; // url rewriting // this needs to load the user before the currentNode is returned context.User = SFGlobal.FetchUser(); context.Items.Add("currentNode", SFGlobal.GetNode(output)); if (context.Items["currentNode"] == null || SFGlobal.GetNode(output) == null) { context.Response.Write("currentNode is null:" + output); context.Response.End(); } context.RewritePath(cs.PageHandler, cs.PageHandler, output); } else { //context.Response.Write("no rewrite"); } }