Convention over configuration
If you Observance this you can easy get ExampleProject.Controllers
because all controller in Controllers folder and if you don't change manually this convention you Safely to get controller's namespace but if you change namespace
public class CustomAuthAttribute : AuthorizeAttribute
{
public string controllerFullName { get; set; }
protected override bool AuthorizeCore(HttpContextBase httpContext)
{
string currentNamespace = string.Empty;
string currentController = string.Empty;
string currentAction = string.Empty;
var routeData = httpContext.Request.RequestContext.RouteData;
currentController = routeData.GetRequiredString("controller"); //Example
currentAction = routeData.GetRequiredString("action"); //Index
currentNamespace = controllerFullName.Substring(0, controllerFullName.IndexOf("." + currentController, System.StringComparison.Ordinal));
return false;
}
public override void OnAuthorization(AuthorizationContext filterContext)
{
controllerFullName = filterContext.Controller.ToString();
base.OnAuthorization(filterContext);
}
}