技术资讯   > 技术文章 > .net2.0构架二级域名的访问形式
[发表时间: 2010-03-21 12:59 ]

全诚商诚多用户版在访问格式上有需要二级域名访问形式的必要性,全诚通过资料考究发现,网络中所提供的解决方案中大都建立在重新定向URL地址,相当于转发,不能实现真正的二级域名访问;或者通过URL地址重写来实现二级域名的访问,这样确实实现了真正的二级域名访问,但是有个致命的缺陷,就是在URL地址通过程序重写的过程中,大大降低了程序运行性能。至此能不能存在第三种方案更有效的去解决二级域名的访问,并且不会影响程序的性能呢,应该有。我们原创了第三种方案,借此贵地发出来。和广大技术朋友们共同探讨和实践!!不足之处请高手极力补充,共同去完善一个完美的属于.net的二级域名访问格式!!!!

全诚商城多用户版的二级域名的访问方案实现原理代码如下:

            string str = System.Web.HttpContext.Current.Request.Url.Host.ToString();

            string aburl = System.Web.HttpContext.Current.Request.Url.AbsoluteUri.ToString();

            string strr = System.Web.HttpContext.Current.Request.QueryString.ToString();

            string strurl = System.Web.HttpContext.Current.Request.Url.PathAndQuery.ToString();

            string[] strlist = str.Split(new char[] { '.' });
            string tb = strlist[0].ToString();


            if (strlist.Length >= 3)
            {


                if (tb.ToLower() == "www" )
                {

                    if (strr.ToLower().Contains("sjid"))
                    {
                        string[] strl = System.Text.RegularExpressions.Regex.Split(strr, "&", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
                        int sid = Convert.ToInt32(System.Text.RegularExpressions.Regex.Split(strl[0], "=", System.Text.RegularExpressions.RegexOptions.IgnoreCase)[1]);
                        if (new ConfigDB().Getissdo() == "1")
                        {
                            if (tb.ToLower() == "192" || tb.ToLower() == "127")
                            {
                                Response.Redirect("http://" + str + "/UserWeb/" + sy.Getmb(sid) + strurl);
                            }
                            else
                            {
                                Response.Redirect("http://" + str.Replace("www", sy.GetSjuserByID(sid)).Replace("cp1", sy.GetSjuserByID(sid)) + strurl);
                            }
                        }
                        else
                        {
                            if (tb.ToLower() == "192" || tb.ToLower() == "127")
                            {
                                Response.Redirect("http://" + str + "/UserWeb/" + sy.Getmb(sid) + strurl);
                            }
                            else
                            {
                                Response.Redirect("" + weburl + "/UserWeb/" + sy.Getmb(sid) + strurl);
                            }
                        }
                    }

                }
                else
                {
                    if (!sy.SupplyMemberNameExistt(strlist[0].ToString()))
                    {

                        System.Web.HttpContext.Current.Response.Write(getym("" + weburl + "/error.aspx"));
                        Response.End();
                        return;

                    }
                    else
                    {

                        SqlDataReader sdr = sy.GetAdminDetailsByname(strlist[0].ToString());
                        string mb = string.Empty;
                        string cid = string.Empty;
                        while (sdr.Read())
                        {
                            mb = sdr["mb"].ToString();

                            cid = sdr["id"].ToString();
                        }
                        sdr.Close();
                        if (!strurl.ToLower().Contains("?"))
                        {
                            if (strurl.ToLower().Contains("html"))
                            {
                                if (strurl.ToLower().Contains("default"))
                                {
                                    Response.Redirect(weburl);
                                    Response.End();
                                    return;
                                }
                                else
                                {
                                    System.Web.HttpContext.Current.Response.Write(getym("" + weburl + "/" + strurl + ""));
                                    Response.End();
                                    return;
                                }
                            }
                            else
                            {
          
                                System.Web.HttpContext.Current.Response.Write(getym("" + weburl + "/UserWeb/" + mb + "/index.aspx?sjid=" + cid + ""));
                                Response.End();
                                return;
                            }

                        }
                        else
                        {
       
                            System.Web.HttpContext.Current.Response.Write(getym("" + weburl + "/UserWeb/" + mb + "/" + strurl + ""));
                            Response.End();
                            return;

                        }
                    }
                }
            }