I'm trying to implement what's seen here: http://www.piotrwalat.net/nhibernate-session-management-in-asp-net-web-api/ but I'm having an issue with my NhSessionManagementAttribute
.
I've set breakpoints on my OnActionExecuting(HttpActionContext actionContext)
to see whether the function was ever being called -- it wasn't.
I double-checked my global.asax.cs
file & found I am in fact registering the ActionFilter
with:
GlobalConfiguration.Configuration.Filters.Add(new NhSessionManagementAttribute());
I have also decorated both my controller class itself, as well as its actions with the attribute to no avail:
public class ClientsController : ApiController { static readonly ClientRepository repository = new ClientRepository(); [NhSessionManagement] public IEnumerable<Client> GetAllClients() { return repository.GetAll(); } [NhSessionManagement] public Client GetClient(int id) { Client client = repository.Get(id); if (client == null) { throw new HttpResponseException( new HttpResponseMessage(HttpStatusCode.NotFound) ); } return client; } }
Why would this action filter not be firing any of the events within?
Web API includes filters to add extra logic before or after action method executes. Filters can be used to provide cross-cutting features such as logging, exception handling, performance measurement, authentication and authorization.
The latest ASP.NET Web API 2.2 package has the following version: "5.2. 0". You can install or update these packages through NuGet. The release also includes corresponding localized packages on NuGet.
If you're working in a project contains both MVC and WebAPI assembilies, could you check what's the namespace your ActionFilterAttribute's namespace. It's fairly confusing cause there are two ActionFilterAttributes under both:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With