【发布时间】:2015-12-20 20:22:06
【问题描述】:
我有一个用 ASP.NET MVC 编写的 CMS。我编写了一个自定义路由处理程序,它查看传入路径并确定将其路由到哪里(即自定义重定向、类别页面、产品页面等)。当前路由存储在 memcached 服务器上的缓存中。一切都很好,直到我们在服务器上获得高负载。然后,我有时会从缓存中检索错误,甚至有时会出现 404 错误。运行需要 5-10 秒的报告也会导致整个服务器挂起
- 我是否应该使用自定义路由处理程序开始?
-
这不都是异步完成的吗?
public IHttpHandler GetHttpHandler(RequestContext requestContext) { var _lock = new Object(); MvcHandler handler = null; var path = requestContext.HttpContext.Request.Path.ToLower().RemoveOutsideSlashes(); var qs = requestContext.HttpContext.Request.QueryString; List<Cache.RouteItem> items; lock (_lock) { var cache = new CacheManager(); items = cache.Routes; } if (!hasPermanentRedirect(path, qs, items, ref requestContext)) { // check for categories first handler = checkForCategory(path, items, ref requestContext); // check for product if (handler == null) handler = checkForProduct(path, items, ref requestContext); // check for webpage if (handler == null) handler = checkForWebPage(path, items, ref requestContext); } if (handler != null) return handler; return new MvcHandler(requestContext); }
【问题讨论】:
-
我理解对了吗,您自己编写
HttpHandler而不是在 MVC 堆栈中使用RouteConfig?
标签: c# asp.net-mvc