krishna mohan
krishna mohan

Reputation: 921

How to check url contains query string or not

I want to check whether the url has querystring values ? or not.

If query string value is not present, if it's a plain url, it should redirect to some other page, so that if somebody accesses the page directly they should be redirected to some other page

protected void Page_Load(object sender, EventArgs e)
{
    if (string.IsNullOrWhiteSpace(Request.QueryString["aspxerrorpath"]))
    {
        uniqueid = Request.QueryString["val"];
    }
    else
    {
        Response.Redirect("proformainvoice.aspx");
    }

    if (!Page.IsPostBack)
    {
        fillproformadata();
    }
}

Upvotes: 1

Views: 8782

Answers (1)

Mairaj Ahmad
Mairaj Ahmad

Reputation: 14624

You can use HasKeys method of Request.QueryString to check if url contains QueryString or not.

bool hasKeys = Request.QueryString.HasKeys();
if(hasKeys)
{
 //your code     
}
else
{
 //your code
}

Upvotes: 3

Related Questions