Elmah 陷入默认路由?

Elmah getting stuck in default route?

我将 Elmah.MVC 添加到我的 MVC 站点,但是当访问 /elmah 时,我的站点陷入重定向循环 /elmah?culture=en - 我认为这是因为我的一个路由配置条目:

    public class 路由配置
    {
        public static void RegisterRoutes(RouteCollection 路由)
        {
            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 的 class 引起的

我的知识有限,不过好像是这个class(我自己加的)在controller激活时连接到request,决定是否修改重定向。

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;
    }
}