开发者

How to get the physical controller class file path of the executing action method?

开发者 https://www.devze.com 2023-01-31 20:40 出处:网络
Assume the current executing action method is Index() in Home controller. From within Index(), how to obtain the physical file pa开发者_如何学Goth of the Home controller? Assume we don\'t know the fil

Assume the current executing action method is Index() in Home controller. From within Index(), how to obtain the physical file pa开发者_如何学Goth of the Home controller? Assume we don't know the file structure until runtime.


The physical file (Controller\Home.cs) might not exist, since the controller is compiled into a .dll, and by convention, is stored in the bin folder.

If it is the .dll you want, probably in the bin folder, or use GetExecutingAssembly from within the controller.

You can find the name of the controller using:

Request.RequestContext.RouteData.Values["controller"];

You can store the location of the .cs files in your Web.Config, that would be enough to find them. (Beware of partial .cs files).

Finding the controller method would be the next step, since finding a method with the right name is not enough. You have to match the parameters and attribute (HttpPost / ActionName).


This will help: Get the Assembly path C#

0

精彩评论

暂无评论...
验证码 换一张
取 消