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;
        }
View Code
 public static string GetCommandName()
        {
            string parameter = string.Empty;
            string command = string.Empty;
            ExtractCommandName(out command, out parameter);
            return command.Replace('/', '_');
        }
View Code
   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;
        }
View Code
   ///从当前请求的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();
        }
View Code

 

posted on 2014-10-30 17:57  随心所意  阅读(136)  评论(0)    收藏  举报