Comments (4)
Can you show us how to reproduce the issue?
It's not a big deal to guard against, but sometimes those checks are just there for testing, not a condition that would normally be hit in runtime. Hence the question - how would you get a null controller in a normal runtime environment?
from autofac.mvc.
Yes, well...I have no idea. That's the problem I was hoping you would have some insight into, such that I wouldn't have to detail our dependency structure and configuration. I was hoping that a null check would be the easy (and correct) solution, just based on what I saw in the base implementation. But here goes...
We use MVCSiteMapProvider for navigation on our site. We recently enabled "Security Trimming", which can show or hide nodes based on AuthorizeAttributes that decorate the routes that the menu nodes point to. This all worked fine when the site was using Windows Authentication.
We recently changed to Forms Auth (we use both in different production environments), and that's when it started breaking. The Stack trace ends with the null reference in AutofacFilterProvider. Now, there could just as likely be a problem in our site map configuration/usage (or even a bug in MVCSiteMapProvider code). I thought as much when I started debugging this, because this is happening upon first visiting the site. The user is redirected to the log-in page, as he is not yet authenticated.
I thought it would have something to do with the user being anonymous. However, when I started debugging the code, I hit a breakpoint in GetFilters() for 3 or 4 controller actions before we hit the action that contained the null Controller property.
Hopefully that's of some help. I'll keep digging in the mean time.
[NullReferenceException: Object reference not set to an instance of an object.]
System.Object.GetType() +0
Autofac.Integration.Mvc.AutofacFilterProvider.GetFilters(ControllerContext controllerContext, ActionDescriptor actionDescriptor) +336
MvcSiteMapProvider.AuthorizeAttributeAclModule.IsAccessibleToUser(IControllerTypeResolver controllerTypeResolver, DefaultSiteMapProvider provider, HttpContext context, SiteMapNode node) +1497
MvcSiteMapProvider.DefaultAclModule.IsAccessibleToUser(IControllerTypeResolver controllerTypeResolver, DefaultSiteMapProvider provider, HttpContext context, SiteMapNode node) +170
MvcSiteMapProvider.DefaultSiteMapProvider.IsAccessibleToUser(HttpContext context, SiteMapNode node) +448
System.Web.StaticSiteMapProvider.GetChildNodes(SiteMapNode node) +334
MvcSiteMapProvider.DefaultSiteMapProvider.FindControllerActionNode(SiteMapNode rootNode, IDictionary`2 values, RouteBase route) +65
MvcSiteMapProvider.DefaultSiteMapProvider.FindSiteMapNode(HttpContext context, RouteData routeData) +705
MvcSiteMapProvider.DefaultSiteMapProvider.FindSiteMapNode(HttpContext context) +122
System.Web.SiteMapProvider.get_CurrentNode() +70
MvcSiteMapProvider.DefaultSiteMapProvider.get_CurrentNode() +141
MvcSiteMapProvider.Web.Html.SiteMapPathHelper.SiteMapPath(MvcSiteMapHtmlHelper helper, String templateName) +48
WOTI.Xift.XiftWebApp.LayoutHelperExtensions.XiftSiteMapPath(HtmlHelper Html) +19
from autofac.mvc.
Okay, it turns out that it was the MvcSiteMapProvider.AuthorizeAttributeAclModule.IsAccessibleToUser() call that was setting the Controller to null. Ultimately, the problem was in our code, as the controller construction was throwing an exception with an anonymous user. The method above swallows the exception and proceeds as though nothing is amiss.
I don't know, frankly, if a null Controller property should be an exceptional condition or not. But you can make that determination on your own time, as this is no longer a pressing need for us.
from autofac.mvc.
I'll leave this open and we can add the check. It makes sense to behave like the base provider though I don't think it would have guaranteed correct behavior for you - if the controller is null it skips filter evaluation entirely, which means the authorization wouldn't necessarily have been calculated correctly.
As soon as you mentioned MvcSiteMapProvider I pretty much knew the issue was going to be there. I've spent a lot of time with MvcSiteMapProvider in the past. The idea is good, but given proper authorization filter eval requires a controller instance (as you're seeing in that default filter attribute provider) I found that we were eating up a lot of memory on every request when we had to actually instantiate every controller in the map just to evaluate whether or not it should show up in the map. I'm not sure if that issue's been resolved; for the projects I was on we ended up writing a different, custom version that didn't require that.
Anyway, glad you figured it out.
from autofac.mvc.
Related Issues (20)
- how can i implement autofac on mvc 5.2 and 4.5.2 framework ? HOT 1
- Get a can not load assembly "System.Web.Mvc, Version=5.1.0.0" error when i put project in a directory name contain "#" HOT 8
- Add .NET Framework 4.5 support to packaging HOT 9
- Update to support .NET 4.5
- How do you register a custom action invoker? HOT 7
- Different resolving from constructor injection and DependencyResolver.Current.GetService HOT 2
- The presence of concurrency issues HOT 2
- RequestLifetimeScopeProvider.EndLifetimeScope throws NullReferenceException when both OWIN middleware and MVC integration HOT 5
- Could not load file or assembly 'System.Web.Mvc, Version=5.1.0.0 HOT 3
- Project still under active development? HOT 3
- Using AutofacServiceLocator on type with InstancePerRequest() causes error HOT 1
- System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection HOT 2
- Integration not compatible with Autofac 5.0 Release Candidate HOT 6
- Exception when requesting the first view HOT 15
- can name injection be supported HOT 1
- Registering one filter type for multiple controllers doesn't work in one statement HOT 1
- Compatibility with Autofac v6 HOT 3
- Appveyor not pushing packages HOT 1
- Upgrade Microsoft.AspNet.Mvc version from 5.10 to a greater version HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from autofac.mvc.