Justin
Justin

Reputation: 33

Get querystring value

I want to make a method in my tools library that request the querystring from the url. I created the following code, but i can't use the HttpContext in a class library.

    public string RequestString(string requestParam, string Default)
    {
        string param = HttpContext.Current.Request.QueryString[requestParam];
        if (param != null)
        {
            return param;
        }
        else
        {
            return Default;
        }
    }

I know it is possible, but i can't remember how...

Upvotes: 0

Views: 5344

Answers (1)

M4N
M4N

Reputation: 96606

You need to add a reference to the System.Web.dll assembly in your class library project.

But of course you will only be able to access the query string when your method is called in the context of a HTTP request.

See this MSDN page for more information about the HttpContext class.

Upvotes: 2

Related Questions