Skip to content

Instantly share code, notes, and snippets.

@halityurttas
Last active September 30, 2023 18:02
Show Gist options
  • Save halityurttas/e8713a1ccaf6f7dd7563 to your computer and use it in GitHub Desktop.
Save halityurttas/e8713a1ccaf6f7dd7563 to your computer and use it in GitHub Desktop.
Get current controller and action name in global.asax
void Application_BeginRequest(object sender, EventArgs e)
{
HttpContextBase context = new HttpContextWrapper(HttpContext.Current);
RouteData rd = RouteTable.Routes.GetRouteData(context);
if (rd != null)
{
string controllerName = rd.GetRequiredString("controller");
string actionName = rd.GetRequiredString("action");
Response.Write("c:" + controllerName + " a:" + actionName);
Response.End();
}
}
@mustafamg
Copy link

Worked, thanks :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment