1.
public class PageInfo { public static PageInfo Detail() { string pageInfoPath = HttpRuntime.AppDomainAppPath + @"Config\PageInfoWiki.config"; string host = HttpContext.Current.Request.Url.Host; XDocument xdoc = XDocument.Load(pageInfoPath); string command = Url.GetCommandName(); var pageInfo = (from page in xdoc.Descendants("pageInfo") where page.Element("command").Value == command && page.Element("domain").Value==host select new PageInfo { Title = page.Element("title").Value, Keywords = page.Element("keywords").Value, Author = page.Element("author").Value, Copyright = page.Element("copyright").Value, Description = page.Element("description").Value }).FirstOrDefault(); return pageInfo; }
public static string GetCommandName() { string parameter = string.Empty; string command = string.Empty; ExtractCommandName(out command, out parameter); return command.Replace('/', '_'); }
public static void ExtractCommandName(out string command, out string parameter) { string commandName = ExtractCommandName(); int slashIndex = commandName.LastIndexOf('/'); if (slashIndex == -1) slashIndex = 0; string exParameter = string.Empty; if (commandName.IndexOf(',') > 0) { int commaIndex = commandName.LastIndexOf(','); exParameter = commandName.Substring(slashIndex + 1, commaIndex - slashIndex - 1); if (slashIndex == 0) { commandName = commandName.Substring(commaIndex + 1, commandName.Length - commaIndex - 1); } else { commandName = commandName.Substring(0, slashIndex + 1) + commandName.Substring(commaIndex + 1, commandName.Length - commaIndex - 1); } } command = (slashIndex > 0) ? commandName.Substring(0, slashIndex) : commandName; parameter = exParameter; }
///从当前请求的Url中拆分出CommandName /// </summary> /// <returns></returns> protected static string ExtractCommandName() { string path = HttpContext.Current.Request.Path; int start = HttpContext.Current.Request.ApplicationPath.Length; if (!HttpContext.Current.Request.ApplicationPath.Equals("/")) start++; int end = path.LastIndexOf('.'); if (end < 0) path = "default"; else path = path.Substring(start, end - start); return path.ToLower(); }
浙公网安备 33010602011771号