我想制作一个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文件应用程序
谢谢!