private void Application_BeginRequest(object sender, System.EventArgs e) { HttpApplication app = ((HttpApplication)(sender)); HttpContext context = app.Context; string r = context.Request.RawUrl; // get the user System.Web.HttpContext.Current.User = SFGlobal.FetchUser(); if (!cs.IsExcluded(r)) // page isn't excluded { if (r.IndexOf(rqcs.AdminDirectory) > 0) // is in the 'admin' directory { bool b = false; foreach (string role in SFGlobal.CurrentUser.Roles) { if (SFGlobal.CurrentUser.IsRoleCMS(role, NodeFactory.RootNode)) { b = true; } } if (!b) { SFGlobal.RedirectToLogin(); } /* * if (!SFGlobal.CurrentUser.IsUserCMS()) * { * SFGlobal.RedirectToLogin(); * } */ } else // process normally { if (context.Items["currentNode"] == null) { throw new Exception("currentNode is null and page isn't excluded from url processing:"); //context.Response.End(); } if (!SFGlobal.CheckUserNodePermission(Permission.View)) // check to see if the user has view permissions { //context.Response.Write("process"); //context.Response.End(); SFGlobal.RedirectToLogin(); } } } }
// 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"); } }