checking virtual sub domains

Posted by Persian. on Stack Overflow See other posts from Stack Overflow or by Persian.
Published on 2011-10-04T12:56:43Z Indexed on 2011/11/16 17:51 UTC
Read the original article Hit count: 192

Filed under:
|

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 .

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 ..

it shows 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.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");
           }
        }

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 ?

© Stack Overflow or respective owner

Related posts about c#

Related posts about ASP.NET