【发布时间】:2009-05-11 19:46:53
【问题描述】:
我想制作一个 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)。我'想要一个只有 .htm 文件的应用程序,带有令牌和 .cs 文件
谢谢!
【问题讨论】:
-
考虑修改代码 sn-p: "public call obj"? “公共 obj(字符串 id)”?
-
我正在考虑修改问题:哪个方法负责解析请求 URL 并选择要实例化的 httphandler。