1

my coding is

if (Request.QueryString["uid"].ToString() != "0")
{
   string dummy  =Request.QueryString["uid"].ToString();
   Label1.Text = dummy;
    Response.Redirect("../Profile/Home1.aspx?uid="+ dummy );
}
else
{
    Label1.Text = "none";
    Session["AccountId"] = 0;
}

my problem is am using in this coding in home page.. if it is the first page in website querystring creates problem.. if the user starts with login page means it works. now i want to avoid the querystring problem.

2 Answers 2

3

you have to fix your if condition to check for null - otherwise you will get an Exception when trying to call ToString() on null:

if(Request.QueryString["uid"] != null &&  Request.QueryString["uid"].ToString() != "0")

But there is a better way to do this - QueryString already returns a string:

if(Request.QueryString["uid"] != null && Request.QueryString["uid"] != "0")
Sign up to request clarification or add additional context in comments.

Comments

0

I know this is old, but for reference.

Request.QueryString[index] returns a string.

The ToString is actually completely redundant, and is causing your problem. (null).toString() results in a null reference exception.

    string uid = Request.QueryString["uid"];
    if (uid != "0") {
        Label1.Text = uid;
        Response.Redirect("../Profile/Home1.aspx?uid="+ uid);
    }
    else {
        Label1.Text = "none";
        Session["AccountId"] = 0;
    }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.