Elmah陷入默认路线?
我添加了Elmah.MVC到我的MVC站点,但是当访问/ elmah时,我的站点被卡在一个重定向循环中/ elmah?culture = en - 我认为这是因为我的一个路由配置条目:
public class RouteConfig { public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); routes.MapRoute( "Default", "{culture}/{controller}/{action}/{id}", new { culture = CultureHelper.GetDefaultCulture(), controller = "Home", action = "SetCulture", id = UrlParameter.Optional } ); } }
我应该如何修改RouteConfig来正确显示/ elmah? 或者我看错了地方?
谢谢 :-)
它是由实现IControllerActivator的名为CultureAwareControllerActivator的类引起的
我的知识是有限的,但似乎这个类(我自己添加的)在控制器被激活时连接到请求并决定是否修改和重定向。
public class CultureAwareControllerActivator : IControllerActivator { public IController Create(RequestContext requestContext, Type controllerType) { string cultureName = requestContext.RouteData.Values["culture"] as string; // Attempt to read the culture cookie from Request if (cultureName == null) cultureName = requestContext.HttpContext.Request.UserLanguages != null && requestContext.HttpContext.Request.UserLanguages.Length > 0 ? requestContext.HttpContext.Request.UserLanguages[0] : null; // obtain it from HTTP header AcceptLanguages // Validate culture name cultureName = CultureHelper.GetImplementedCulture(cultureName); // This is safe if (requestContext.RouteData.Values["culture"] as string != cultureName && (string) requestContext.RouteData.Values["controller"] != "Elmah") { // Force a valid culture in the URL requestContext.RouteData.Values["culture"] = cultureName.ToLowerInvariant(); // lower case too // Redirect user requestContext.HttpContext.Response.RedirectToRoute(requestContext.RouteData.Values); } // Modify current thread's cultures Thread.CurrentThread.CurrentCulture = new CultureInfo(cultureName); Thread.CurrentThread.CurrentUICulture = Thread.CurrentThread.CurrentCulture; return DependencyResolver.Current.GetService(controllerType) as IController; } }链接地址: http://www.djcxy.com/p/74353.html
上一篇: Elmah getting stuck in default route?
下一篇: MVC 3 on IIS 7 returns 404 for MVC extensionless url requests