gpt4 book ai didi

c# - 使用 MVC 5 属性路由的性能不佳和网站速度慢

转载 作者:太空狗 更新时间:2023-10-29 23:50:51 24 4
gpt4 key购买 nike

我正在使用 mvc5 在 Azure 上开发一个网站。我使用属性路由,在 Controller 上使用路由和路由前缀。我调用 action.link 助手。我没有命名我的路线。

我在我的 route.config 中做了以下操作:

routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapMvcAttributeRoutes();
routes.LowercaseUrls = true;
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);

我的 Controller 是这样的:

[OutputCache(Duration = 600, Location = System.Web.UI.OutputCacheLocation.Client)]
[RoutePrefix("istanbul/kadikoy")]
[Route("{action=index}")]
public class KadikoyController : Controller
{

public ActionResult Index()
{
return View();
}

[Route("kadikoy-tarihi")]
public ActionResult KadikoyTarihi()

我的服务器响应时间非常非常差,即 9.6 秒

如果我注释掉属性路由代码,使用默认路由,我有 2.1 秒的服务器响应时间。

感谢您的回复。

最佳答案

事实证明,此操作真正昂贵的部分不是映射您的属性路由,而是在此之前 MVC 需要创建 ControllerFactory 并检索所有 Controller 类型。该过程在我的项目中占 1245 毫秒,而其余 MapMvcAttributeRoutes() 函数大约需要 45 毫秒。我的猜测是,如果您不使用属性路由,则会根据需要找到 Controller ,而不是一次找到所有 Controller 。

关于c# - 使用 MVC 5 属性路由的性能不佳和网站速度慢,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28409529/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com