代码之家  ›  专栏  ›  技术社区  ›  missaghi

如何定义没有web.config或httpmodule的端点?

  •  1
  • missaghi  · 技术社区  · 16 年前

    我想制作一个httphandlers的RESTful应用程序,而不必通过在web.config中创建一个条目来定义每个端点,我希望将属性附加到类构造函数的样式,例如:

    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)
      }
    }
    

    而不是

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

    现在,我在web.config中有100个端点:(我宁愿在类中定义它们。我也不想制作额外的文件(.asmx)。我想要一个带有令牌和.cs文件的.htm文件应用程序

    谢谢!

    1 回复  |  直到 15 年前
        1
  •  1
  •   Cheeso    16 年前

    您可以使用自定义ServiceHost自动注册端点等,该服务主机将重写applyconfiguration()方法,然后虚拟化配置,使其不必位于web.config文件中。

    Here's a starting point . 它并不完全满足您的需要,但它说明了虚拟化配置的概念。