My code has the following in an Action Method:
catch (Exception e)
{
log(e);
return Content(ExceptionExtensions.GetFormattedErrorMessage(e));
}
in the ExceptionExtensions.GetFormattedErrorMessage(e) function I would like to be able to return a different message depending if it is a user in the “Guest” role or the “Admin” role. Am I able to do this in that function or would I need to somehow find out if the user is in a role when in the controller and then pass that information to the other function?
you would need access to the HTTPContext and I dont think it will be available in the class that houses your action method, one way to go about this would be to pass the HttpContext to the function itself or you could verify if the user is an admin or a field user and then pass it to your function..
To verify the Role you can use the following method:
Also check if you have access to the HttpContext in your method.