0

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

M4N
  • 94,805
  • 45
  • 217
  • 260
Justin
  • 33
  • 1
  • 3
  • Do you have access to the URL? Also, you can use `HttpContext.Current` from a class library, only it will be `null` when you're not in a a web request. – Matthew Aug 08 '12 at 20:38

1 Answers1

2

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.

M4N
  • 94,805
  • 45
  • 217
  • 260
  • Thanks for the reply, i already added System.Web.Dll to the references but only in the wrong project... That's why it didn't work.. Maby i need to take a small break. Haha! Thanks again :) – Justin Aug 08 '12 at 21:02