Is there an ASP.NET way to add parameters to the URL?

Posted on 2008-01-29
Medium Priority
Last Modified: 2013-11-07
I have an onclick button that redirects the user to another page, but I need to add a parameter to the URL for the redirect. Considering all the scenarios, I have nested if statements to get the URL right like this:

        if (!Request.RawUrl.Contains("sticky=1"))
            if (Request.RawUrl.Contains("?"))
                Response.Redirect(Request.RawUrl + "&sticky=1");
                Response.Redirect(Request.RawUrl + "?sticky=1");

I was hoping there was something built into .NET to add parameters to the URL, like a one liner or something. Can .NET take care of this or do I got to leave the mess like that? I'm worried there's some other scenario I'm not taking into account.
Question by:bemara57
LVL 23

Accepted Solution

Stacy Spear earned 2000 total points
ID: 20770330

Author Comment

ID: 20771859
Thx, I just ended up doing this:

    public static string AddUrlParam(string url, string param)
        if (!url.Contains(param))
            if (url.Contains("?"))
                url += "&" + param;
                url += "?" + param;

        return url;

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The PowerShell Core 6.0 of .NET release is just the beginning. The upcoming PowerShell Core 6.1 would have artificial intelligence and internet of things capabilities. So many things to look forward to in the upcoming release.
The video will let you know the exact process to import OST/PST files to the cloud based Office 365 mailboxes. Using Kernel Import PST to Office 365 tool, one can quickly import numerous OST/PST files to Office 365. Besides this, the tool also comes…
When you have multiple client accounts to manage, it often feels like there aren’t enough hours in the day. With too many applications to juggle, you can’t focus on your clients, much less your growing to-do list. But that doesn’t have to be the cas…

627 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question