文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>MVC 二级域名实现

MVC 二级域名实现

时间:2010-12-10  来源:依晨

1.创建HttpHandler 处理

#region 二级域名处理
    public class Domain_Url : IHttpHandler
    {
        public RequestContext RequestContext { get; private set; }

        public Domain_Url(RequestContext Content)
        {
            this.RequestContext = Content;
        }

        public virtual void ProcessRequest(HttpContext context)
        {

            string url = context.Request.Url.ToString().ToLower();
            url = url.Substring(url.IndexOf("http://") + 7);
            string custom_Prefix = url.Substring(0, url.IndexOf('.'));           

            //服务器
            if (custom_Prefix.Equals("www", StringComparison.CurrentCultureIgnoreCase))
            {
                context.Response.Redirect("/Home/Index");
                context.Response.End();
                return;
            }
           
            Tranlit.DAL.TranlitDB db = new Tranlit.DAL.TranlitDB();


            var shop = db.Shop.FirstOrDefault(s=>s.ShopDomain == custom_Prefix);
            if (shop != null)
            {
                context.Response.Redirect("/mall/shopIndex?shopId=" + shop.AutoId);
                context.Response.End();
                return;
            }

           
            context.Response.Redirect("/Home/Index");

            var host = context.Request.Url.Host;
            if (!(host.Equals("www.chuanlidamai.com", StringComparison.CurrentCultureIgnoreCase) ||
                host.Equals("www.cl398.com", StringComparison.CurrentCultureIgnoreCase)))
                host = "www.cl398.com";


        }
        public bool IsReusable
        {
            get { return false; }
        }
    }

    public class DomainHandler : IRouteHandler
    {
        public IHttpHandler GetHttpHandler(RequestContext requestContext)
        {
            return new Domain_Url(requestContext); //返回自定义的HttpHandler
        }

    }
    #endregion

2.修改 Global.aspx.cs

routes.Add(new Route("", (new Tranlit.BLL.UrlRouting.DomainHandler())));

相关阅读 更多 +
排行榜 更多 +
辰域智控app

辰域智控app

系统工具 下载
网医联盟app

网医联盟app

运动健身 下载
汇丰汇选App

汇丰汇选App

金融理财 下载