Is there an event that raises after a View/PartialView executes in ASP.NET MVC 2 RC2?

Posted by sabanito on Stack Overflow See other posts from Stack Overflow or by sabanito
Published on 2010-02-23T00:12:40Z Indexed on 2010/04/03 6:43 UTC
Read the original article Hit count: 371

Filed under:
|

I have the following problem:

We have an ASP.NET MVC 2 RC 2 application that programmatically impersonates an AD Account that the user specifies at logon. This account is used to access the DB. At first we had the impersonating code in the begin_request and we were undoing the impersonation at the end_request, but when we tried to use IIS 7.5 in integrated mode, we learned that it's not possible to impersonate in the Global.asax so we tried different things.

We have succesfully moved our code from the BeginRequest to the ActionExecuting event and the EndRequest to the ResultExecuted, and now, about 80% of our code works.

We've just discovered that since we're passing the Entity Framework objects as models for our views, there's this remaining 20% that won't work because some Navigation Properties are not loaded when the view begins it's execution, so we're getting connection exceptions from Sql Server.

Is there any event or method that executes AFTER the view, so we can undo the impersonation in it? We thought ResultExecuted will do just that, but it doesn't.

We've been told that passing the plain Entities into the view as models is not a good idea, but we have A LOT of views that may have this problem and there's not automated way to know it. If some of you could explain why it's not a good idea, maybe we can convince the team to fix it!

© Stack Overflow or respective owner

Related posts about ASP.NET

Related posts about asp.net-mvc-2-rc2