checking virtual sub domains
<p>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 .</p>

<p>on local system it works finely .. but when I upload it on server it not works .. of course I change the commented place to uncomment for test .. but it's not working ..</p>

<p>it shows this error :</p>

<blockquote>
  <p>Object reference not set to an instance of an object.</p>
</blockquote>

<p>My code is this in page load :</p>

<pre><code>        //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");
           }
        }
</code></pre>

<p>and my class :</p>

<pre><code>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 &lt; 10)
                {
                    Blogger = null;
                }
            }
        }

        return Blogger;
    }
</code></pre>

<p>Which place if my code has problem ?</p>
