I want to get the current method name of my ASP.NET Core
controller
I have tried getting the method name through reflection:
[HttpGet]
The C# 5.0 CallerMemberName attribute may do the trick. (I haven't tested this from an async method; it works from a regular call)
private static string GetCallerMemberName([CallerMemberName]string name = "")
{
return name;
}
Then call it from your code:
[HttpGet]
public async Task CreateProcess(int catId)
{
string methodName = GetCallerMemberName();
Note that you don't need to pass anything to the method.