Peter
Peter

Reputation: 38495

Is there any way to pass a parameter from web.config to HttpHandler

Is there any way to set the Parameter property from web.config?

public class TestHttpHandler : IHttpHandler
{

    public bool IsReusable
    {
        get { return true; }
    }

    public string Parameter
    { get; set; }

    public void ProcessRequest(HttpContext context)
    {
        context.Response.Write(Parameter);
    }
}

If i do the following it just crashes.

<handlers>
  <add name="Test" verb="*" path="/Manual/*" 
       type="Test.TestHttpHandler, Test" Parameter="test1234 "/>
</handlers>

Upvotes: 0

Views: 351

Answers (1)

Peter Hahndorf
Peter Hahndorf

Reputation: 11222

Parameter is not a valid attribute for the handlers/add note. Just adding a property with the same name to your handler class doesn't make it magically work.

You can not pass a parameter directly in the handler definition, but within the code of your handler class you have full access to any other configuration data in web.config; any AppSetting or your own ConfigSections.

Upvotes: 1

Related Questions