4
我在通過@Aviv在這篇文章中描述的問題: http://www.devtrends.co.uk/blog/donut-output-caching-in-asp.net-mvc-3#125的NullReferenceException在DevTrends.MvcDonutCaching.KeyGenerator.GenerateKey
我找了錯誤這裏和Codeplex,但沒有找到。
環境是中等信任!
路線public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.IgnoreRoute("{*favicon}", new { favicon = @"(.*/)?favicon.ico(/.*)?" });
routes.IgnoreRoute("elmah.axd");
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional }, // Parameter defaults
new[] { "LetsGo.Controllers" }
);
}
控制器
[DonutOutputCache(CacheProfile = "StaticPage")]
public ActionResult Index()
{
return View(_themeParty.Repository.Query().Published(true).ToList());
}
[ChildActionOnly]
[DonutOutputCache(CacheProfile = "DataCache")]
public PartialViewResult Subsidiaries() { return PartialView(_subsidiaries.Repository.Query().Published().ToList()); }
的Web.config
<caching>
<outputCacheSettings>
<outputCacheProfiles>
<add name="DataCache" enabled="true" duration="10800" varyByParam="*" />
<add name="StaticPage" enabled="true" duration="21600" varyByParam="*" />
<add name="ByHeader" enabled="true" duration="300" varyByHeader="*" />
</outputCacheProfiles>
</outputCacheSettings>
</caching>
_Layout.cshtml
...
@Html.Action("Subsidiaries", "Home", new { area = "" })
...
完整的錯誤
Server Error in '/LetsGo' Application.
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[NullReferenceException: Object reference not set to an instance of an object.]
DevTrends.MvcDonutCaching.KeyGenerator.GenerateKey(ControllerContext context, CacheSettings cacheSettings) +777
DevTrends.MvcDonutCaching.DonutOutputCacheAttribute.ExecuteCallback(ControllerContext context, Boolean hasErrors) +43
System.Web.Mvc.ControllerActionInvoker.InvokeExceptionFilters(ControllerContext controllerContext, IList`1 filters, Exception exception) +168
System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +652
System.Web.Mvc.Controller.ExecuteCore() +161
System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) +304
System.Web.Mvc.<>c__DisplayClassb.<BeginProcessRequest>b__5() +61
System.Web.Mvc.Async.<>c__DisplayClass1.<MakeVoidDelegate>b__0() +19
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +461
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +370
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.272
嗨@Riderman,你有沒有設法解決它? – ysrb 2012-04-29 03:52:17