检查虚拟子域

本文关键字:虚拟 检查 | 更新日期: 2023-09-27 18:10:19

我创建了一个项目,检查子域并重定向到现有的子域(用户名),但我无法找出为什么当用户名在数据库中无法显示它。

在本地系统上工作得很好。但是当我把它上传到服务器上它不工作…当然,为了测试,我将注释的地方改为取消注释。但它不工作…

显示如下错误:

对象引用未设置为对象的实例。

我的代码是这样的页面加载:

        //Uri MyUrl = new Uri(Request.Url.ToString());
        //string Url = MyUrl.Host.ToString();
        Uri MyUrl = new Uri("http://Subdomain.Mydomain.com/");
        string Url = MyUrl.Host.ToString();
        string St1 = Url.Split('.')[0];
        if ((St1.ToLower() == "Mydomain") || (St1.ToLower() == "Mydomain"))
        {
            Response.Redirect("Intro.aspx");
        }
        else if (St1.ToLower() == "www")
        {
            string St2 = Url.Split('.')[1];
            if ((St2.ToLower() == "Mydomain") || (St2.ToLower() == "Mydomain"))
            {
                Response.Redirect("Intro.aspx");
            }
            else
            {
                object Blogger = ClsPublic.GetBlogger(St2);
                if (Blogger != null)
                {
                    lblBloger.Text = Blogger.ToString();
                    if (Request.QueryString["id"] != null)
                    {
                        GvImage.DataSourceID = "SqlDataSourceImageId";
                        GvComments.DataSourceID = "SqlDataSourceCommentsId";
                        this.BindItemsList();
                        GetSubComments();
                    }
                    else
                    {
                        SqlConnection scn = new SqlConnection(ClsPublic.GetConnectionString());
                        SqlCommand scm = new SqlCommand("SELECT TOP (1) fId FROM tblImages WHERE (fxAccepted = 1) AND (fBloging = 1) AND (fxSender = @fxSender) ORDER BY fId DESC", scn);
                        scm.Parameters.AddWithValue("@fxSender", lblBloger.Text);
                        scn.Open();
                        lblLastNo.Text = scm.ExecuteScalar().ToString();
                        scn.Close();
                        GvImage.DataSourceID = "SqlDataSourceLastImage";
                        GvComments.DataSourceID = "SqlDataSourceCommentsWId";
                        this.BindItemsList();
                        GetSubComments();
                    }
                    if (Session["User"] != null)
                    {
                        MultiViewCommenting.ActiveViewIndex = 0;
                    }
                    else
                    {
                        MultiViewCommenting.ActiveViewIndex = 1;
                    }
                }
                else
                {
                    Response.Redirect("Intro.aspx");
                }
            }
        }
        else
        {
           object Blogger = ClsPublic.GetBlogger(St1);
           if (Blogger != null)
           {
               lblBloger.Text = Blogger.ToString();
               if (Request.QueryString["id"] != null)
               {
                   GvImage.DataSourceID = "SqlDataSourceImageId";
                   GvComments.DataSourceID = "SqlDataSourceCommentsId";
                   this.BindItemsList();
                   GetSubComments();
               }
               else
               {
                   SqlConnection scn = new SqlConnection(ClsPublic.GetConnectionString());
                   SqlCommand scm = new SqlCommand("SELECT TOP (1) fId FROM tblImages WHERE (fxAccepted = 1) AND (fBloging = 1) AND (fxSender = @fxSender) ORDER BY fId DESC", scn);
                   scm.Parameters.AddWithValue("@fxSender", lblBloger.Text);
                   scn.Open();
                   lblLastNo.Text = scm.ExecuteScalar().ToString();
                   scn.Close();
                   GvImage.DataSourceID = "SqlDataSourceLastImage";
                   GvComments.DataSourceID = "SqlDataSourceCommentsWId";
                   this.BindItemsList();
                   GetSubComments();
               }
               if (Session["User"] != null)
               {
                   MultiViewCommenting.ActiveViewIndex = 0;
               }
               else
               {
                   MultiViewCommenting.ActiveViewIndex = 1;
               }
           }
           else
           {
               Response.Redirect("Intro.aspx");
           }
        }

和我的班级:

public static object GetBlogger(string User)
    {
        SqlConnection scn = new SqlConnection(ClsPublic.GetConnectionString());
        SqlCommand scm = new SqlCommand("SELECT fUsername FROM tblMembers WHERE fUsername = @fUsername", scn);
        scm.Parameters.AddWithValue("@fUsername", User);
        scn.Open();
        object Blogger = scm.ExecuteScalar();
        if (Blogger != null)
        {
            SqlCommand sccm = new SqlCommand("SELECT COUNT(fId) AS Exp1 FROM tblImages WHERE (fxSender = @fxSender) AND (fxAccepted = 1)", scn);
            sccm.Parameters.AddWithValue("fxSender", Blogger);
            object HasQuty = sccm.ExecuteScalar();
            scn.Close();
            if (HasQuty != null)
            {
                int Count = Int32.Parse(HasQuty.ToString());
                if (Count < 10)
                {
                    Blogger = null;
                }
            }
        }
        return Blogger;
    }

如果我的代码有问题在哪里

检查虚拟子域

如果它在本地工作得很好,我猜服务器中的URL与它有关。

你是否能够准确地指出你在哪里得到"对象引用未设置为对象的实例"异常?这将有助于找到问题所在。

无论如何检查这个SO问题,其中提到Request.Url.ToString()可能在某些情况下表现不同(检查接受的答案)→tostring()返回域

嵌套的机器名