开发者

virtual sub domains has error

I create a project that check the sub domain and redirect to the exist subdomain ( username ) but I can't find out why when the username is in database it can't show it and show this error :

Object reference not set to an instance of an object.

My code is this in page load :

            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.AddWith开发者_高级运维Value("@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");
               }
            }

and my class :

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;
    }

Which place if my code has problem ?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜