如何获取为当前执行的httphandler配置的路径?

时间:2022-05-19 07:22:58

Consider an HttpHandler that can be configured for multiple paths. But based on the path that matched a url i could be able to select the settings to apply.

考虑一个可以配置多个路径的HttpHandler。但根据匹配网址的路径,我可以选择要应用的设置。

I don't want to pass parameters in the url.

我不想在url中传递参数。

2 个解决方案

#1


I don't have time right now to write a complete example, but I guess this would be the way to go:

我现在没有时间写一个完整的例子,但我想这是要走的路:

  • Read Web.config;
  • Get locations;
  • Loop through locations;
  • 循环通过位置;

  • If location uri matches the current uri (get it from System.Web.HttpContext.Current), then you have the current path;
  • 如果location uri与当前的uri匹配(从System.Web.HttpContext.Current获取),那么你有当前的路径;

  • Use the current path to retrieve settings from wherever you stored them.
  • 使用当前路径从存储它们的任何位置检索设置。

Good luck.

#2


Thanks. I have done that and it works well. I also made use of the reflector tool to see how the handler mapping match is made. There seems to be another challenge i have come across. There different ways to configure httphandlers depending on the type of application pool. Is there a general way to get configuration data of the current pool httphandlers?

谢谢。我已经做到了,效果很好。我还使用了反射器工具来查看处理程序映射匹配是如何进行的。似乎我遇到了另一个挑战。根据应用程序池的类型,有不同的方法来配置httphandlers。是否有一般方法来获取当前池httphandlers的配置数据?

#1


I don't have time right now to write a complete example, but I guess this would be the way to go:

我现在没有时间写一个完整的例子,但我想这是要走的路:

  • Read Web.config;
  • Get locations;
  • Loop through locations;
  • 循环通过位置;

  • If location uri matches the current uri (get it from System.Web.HttpContext.Current), then you have the current path;
  • 如果location uri与当前的uri匹配(从System.Web.HttpContext.Current获取),那么你有当前的路径;

  • Use the current path to retrieve settings from wherever you stored them.
  • 使用当前路径从存储它们的任何位置检索设置。

Good luck.

#2


Thanks. I have done that and it works well. I also made use of the reflector tool to see how the handler mapping match is made. There seems to be another challenge i have come across. There different ways to configure httphandlers depending on the type of application pool. Is there a general way to get configuration data of the current pool httphandlers?

谢谢。我已经做到了,效果很好。我还使用了反射器工具来查看处理程序映射匹配是如何进行的。似乎我遇到了另一个挑战。根据应用程序池的类型,有不同的方法来配置httphandlers。是否有一般方法来获取当前池httphandlers的配置数据?