How can I define an endpoint without web.config or httpModule?

I would like to make a RESTful application for HTTP handlers without having to define each endpoint by creating an entry in the web.config file, I would like to style the attaching of attributes to the constructor of the class like:

public class obj : IHttpHandler
{
  [WebGet(UriTemplate = "/accounts/{id}")]
  public obj(string id)
  {
     // this is just an eg, it worild normally include caching and 
     // a template system
     String html = File.ReadAllText("/accounts/accounts.htm");
     html.replace("id", id);
     httpcontext.current.response.write(html)
  }
}

      

instead

<httpHandlers>
      <clear />
      <add verb="GET" path="/accounts/*" type="MyApp.obj" />
</httphandlers>

      

The way I am doing it now, I have 100 endpoints in the web.config :( I would rather define them in a class. And I also don't want to create additional files (.asmx). 'D as an application only .htm files with tokens and .cs files

Thanks!

+1


a source to share


1 answer


You can automate the registration of endpoints, etc. using a custom ServiceHost that overrides the ApplyConfiguration () method, which then virtualizes the configuration so it isn't in the web.config file.



Here is the starting point . It doesn't do what you want, but it does illustrate the concept of configuration virtualization.

+1


a source







All Articles