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#
精彩评论