.NET如何在代码中动态配置Handler?

Charger1991 2017-04-25 10:53:41
在config里是下面这种配置,如何在代码中配置


<system.web>

<httpHandlers>

<add path="xxx.ashx" verb="*" type="xxx" />

</httpHandlers>

</system.web>

<system.webServer>

<handlers>

<add name="xxx.ashx" path="xxx.ashx" verb="*" type="xxx" />

</handlers>

</system.webServer>
...全文
141 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
Charger1991 2017-04-25
  • 打赏
  • 举报
回复
引用 1 楼 hanjun0612 的回复:
不是太确定,因为我没这么配置过
SystemWebSectionGroup s = new SystemWebSectionGroup();
            s.HttpHandlers.Handlers.Add(new HttpHandlerAction() { Path = "xxx.ashx", Type = "xxx", Verb = "*", Validate = true });
这个不行,会报一个“在将 ConfigurationSectionGroup 添加到属于类配置实例的节组之前,不能对它进行编辑”的错。有没有web.config代码配置的相关资料推荐呢,之前一直是在文件里写,这次情况比较特殊没有配置文件。。
正怒月神 2017-04-25
  • 打赏
  • 举报
回复
不是太确定,因为我没这么配置过
SystemWebSectionGroup s = new SystemWebSectionGroup();
            s.HttpHandlers.Handlers.Add(new HttpHandlerAction() { Path = "xxx.ashx", Type = "xxx", Verb = "*", Validate = true });
vac_LJ 2017-04-25
  • 打赏
  • 举报
回复
楼主,你这是干嘛?

110,529

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧