当前位置: 首页 > news >正文

如何搭建静态网站wordpress汉化主题

如何搭建静态网站,wordpress汉化主题,网站自适应手机端,汽车维修东莞网站建设自从微软发布 ASP.NET MVC 和routing engine (System.Web.Routing)以来#xff0c;就设法让我们明白你完全能控制URL和routing#xff0c;只要与你的application path相结合进行扩展#xff0c;任何问题都迎刃而解。如果你需要在所处的域或者子域处理数据标记的话#xff0…自从微软发布 ASP.NET MVC 和routing engine (System.Web.Routing)以来就设法让我们明白你完全能控制URL和routing只要与你的application path相结合进行扩展任何问题都迎刃而解。如果你需要在所处的域或者子域处理数据标记的话强制使用Default。 遗憾的是ASP.NET MVC是基于虚拟目录的在实际项目却有各种各样的需求方案。 例如 1应用程序是多语言的像cn.example.com应该被匹配到“www.{language}example.com”路由上。 2应用程序是多用户的像username.example.com应该被匹配到“www.{clientname}.example.com”路由上。 3应用程序是多子域的像mobile.example.com应该被匹配到www.{controller}.example.com/{action}....” 。 坐下来深呼吸开始我们ASP.NET MVC的神奇之旅吧。 定义routes   下面是我们定义简单的route不带任何controller控制的route   routes.Add(DomainRoute, new DomainRoute( home.example.com, // Domain with parameters{action}/{id},    // URL with parametersnew { controller  Home, action  Index, id   }  // Parameter defaults)); 另一个例子是用我们的controller控制域名   routes.Add(DomainRoute, new DomainRoute( {controller}.example.com,     // Domain with parameters br /    {action}/{id},    // URL with parametersnew { controller  Home, action  Index, id   }  // Parameter defaults)); 打算用controller 和action完全控制域名   routes.Add(DomainRoute, new DomainRoute( {controller}-{action}.example.com,     // Domain with parameters{id},    // URL with parametersnew { controller  Home, action  Index, id   }  // Parameter defaults)); 接下来是多语言route routes.Add(DomainRoute, new DomainRoute( {language}.example.com,     // Domain with parameters{controller}/{action}/{id},    // URL with parametersnew { language  en, controller  Home, action  Index, id   }  // Parameter defaults)); HtmlHelper 扩展方法 因为我们不希望所有的URL所产生HtmlHelper ActionLink要使用full URLs第一件事我们会添加一些新的ActionLink其中载有boolean flag是否要full URLs或没有。利用这些现在您可以添加一个链接到一个Action如下   %Html.ActionLink(About, About, Home, true)% 跟你以往的习惯没有什么不同,不是吗以下是一小段代码:   public static class LinkExtensions { public static string ActionLink(this HtmlHelper htmlHelper, string linkText, string actionName, string controllerName, bool requireAbsoluteUrl)     { return htmlHelper.ActionLink(linkText, actionName, controllerName, new RouteValueDictionary(), new RouteValueDictionary(), requireAbsoluteUrl);     } // more of these public static string ActionLink(this HtmlHelper htmlHelper, string linkText, string actionName, string controllerName, RouteValueDictionary routeValues, IDictionarystring, object htmlAttributes, bool requireAbsoluteUrl)     { if (requireAbsoluteUrl)         {             HttpContextBase currentContext  new HttpContextWrapper(HttpContext.Current);             RouteData routeData  RouteTable.Routes.GetRouteData(currentContext);             routeData.Values[controller]  controllerName;             routeData.Values[action]  actionName;             DomainRoute domainRoute  routeData.Route as DomainRoute; if (domainRoute ! null)             {                 DomainData domainData  domainRoute.GetDomainData(new RequestContext(currentContext, routeData), routeData.Values); return htmlHelper.ActionLink(linkText, actionName, controllerName, domainData.Protocol, domainData.HostName, domainData.Fragment, routeData.Values, null);             }         } return htmlHelper.ActionLink(linkText, actionName, controllerName, routeValues, htmlAttributes);     } } 在这没什么特别的有许多的扩展方法把扩展的URL加到域名上。这是一个预设ActionLink helpers我的精神食粮来了DomainRoute class详见Dark Magic Dark magic 瞥眼之间您可能已经看到了我的DomainRoute类代码段。这个类实际上是提取子域并增加了象征性支持域部分的传入的URL 我们将扩展基类它已经给了我们一些属性和方法但是我们得重写他们   public class DomainRoute : Route {  //  public string Domain { get; set; } //  public override RouteData GetRouteData(HttpContextBase httpContext)     { // 构造regex        domainRegex  CreateRegex(Domain);         pathRegex  CreateRegex(Url); // 请求信息string requestDomain  httpContext.Request.Headers[host]; if (!string.IsNullOrEmpty(requestDomain))         { if (requestDomain.IndexOf(:)  0)             {                 requestDomain  requestDomain.Substring(0, requestDomain.IndexOf(:));             }         } else        {             requestDomain  httpContext.Request.Url.Host;         } string requestPath  httpContext.Request.AppRelativeCurrentExecutionFilePath.Substring(2)  httpContext.Request.PathInfo; //匹配域名和路由        Match domainMatch  domainRegex.Match(requestDomain);         Match pathMatch  pathRegex.Match(requestPath);// Route 数据        RouteData data  null; if (domainMatch.Success  pathMatch.Success)         {             data  new RouteData(this, RouteHandler);// 添加默认选项if (Defaults ! null)             { foreach (KeyValuePairstring, object item in Defaults)                 {                     data.Values[item.Key]  item.Value;                 }             } // 匹配域名路由for (int i  1; i  domainMatch.Groups.Count; i)             {                 Group group  domainMatch.Groups[i]; if (group.Success)                 { string key  domainRegex.GroupNameFromNumber(i); if (!string.IsNullOrEmpty(key)  !char.IsNumber(key, 0))                     { if (!string.IsNullOrEmpty(group.Value))                         {                             data.Values[key]  group.Value;                         }                     }                 }             } // 匹配域名路径for (int i  1; i  pathMatch.Groups.Count; i)             {                 Group group  pathMatch.Groups[i]; if (group.Success)                 { string key  pathRegex.GroupNameFromNumber(i); if (!string.IsNullOrEmpty(key)  !char.IsNumber(key, 0))                     { if (!string.IsNullOrEmpty(group.Value))                         {                             data.Values[key]  group.Value;                         }                     }                 }             }         } return data;     } public override VirtualPathData GetVirtualPath(RequestContext requestContext, RouteValueDictionary values)     { return base.GetVirtualPath(requestContext, RemoveDomainTokens(values));     } public DomainData GetDomainData(RequestContext requestContext, RouteValueDictionary values)     { // 获得主机名string hostname  Domain; foreach (KeyValuePairstring, object pair in values)         {             hostname  hostname.Replace({  pair.Key  }, pair.Value.ToString());         }// Return 域名数据return new DomainData         {             Protocol  http,             HostName  hostname,             Fragment          };     }// }   哇这是一串按照我们定义的route转换传入请求的URL到tokens的代码我们这样做是转换{controller}和按照regex然后再尝试匹配route规则在我们的DomainRoute class里还有其他的helper方法需要更多的功能可以自己研究扩展。 附代码附件如果要在使用Visual Studio开发Web服务器务必添加把二级域名添加到hosts文件貌似本地测试不用原文地址http://blog.maartenballiauw.be/post/2009/05/20/ASPNET-MVC-Domain-Routing.aspx其实有的人为什么要这么麻烦用这种方式URL重写或者二级域名直接绑定都可以。但是既然微软给url rouring就应该能做到。转载于:https://www.cnblogs.com/haiyabtx/archive/2013/04/02/2996097.html
http://www.sadfv.cn/news/189919/

相关文章:

  • 济南 网站定制哪个视频网站做直播销售
  • 网站开发简历项目苏州找工作
  • 招网站建设人员天津建站管理系统信息
  • 网站设计软件开发招聘网站建设规划书
  • 广州网站开发系统获取网站服务器信息
  • 网站开发运营经理微信公众号的网站开发
  • 做网站程序破解空间网站
  • 网页设计相关网站seo快速排名软件网址
  • 中小企业营销型网站建设网站开发研究的方法与技术路线
  • 网站术语郑州网站建设招聘
  • 给公司在百度上做网站著名的国外设计网站有哪些
  • 网站免费下载安装大全手机版照片视频制作网站
  • 网站的需求分析怎么写国家备案网查询系统
  • 网站网络投票建设模板临沂品牌网站推广
  • 如何给网站刷流量企业管理咨询考试题及答案
  • 网站系统里不能打印哈尔滨市工程信息网
  • 厦门 网站制作我想做自己网站怎么做
  • dede如何制作网站地图手机ps抠图软件下载
  • 门户网站开发语言千库网登录入口
  • 微信网站搭建多少钱湛江市网站建设
  • 咸宁市做网站笔记本网站开发背景
  • 怎么办网站平台做网站用什么后缀好
  • 做网站刷东西网站根据城市做二级目录
  • 免费网站赚钱win7系统如何重装wordpress
  • 商务电商网站建设南皮县网站建设价格
  • 织梦菜谱网站模板免费下载排行榜123网
  • 做网络平台的网站有哪些wordpress 主题 排行榜
  • 网站安全检测中心网站做下cdn
  • 去哪找做网站的人网站收录后才可以做排名吗
  • 物流公司网站源码建设介绍网站