누구나 전에 이런 걸 보았습니까? 기본적으로 저장소 패턴을 통해 데이터베이스를 쿼리하고 ViewData에 일부 데이터를 추가 한 다음 뷰를 반환하는 컨트롤러에 대한 작업이 있습니다. 그러나 어떤 이유로이 조치는 요청 당 번이 입니다.요청 당 4 번 실행하는 ASP.NET MVC 컨트롤러 동작
routes.MapRoute(
"SlugsAfterId",
"{controller}.mvc/{action}/{id}/{slug}",
new { controller = "Products", action = "Browse", id = "" }
);
// The default route that comes with ASP.NET MVC
routes.MapRoute(
"Default", // Route name
"{controller}.mvc/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = "" } // Parameter defaults
);
사람이 아무 되거 수 다음과 같이
public ActionResult Details(int id, string slug) {
Product p = productRepository.GetProduct(id);
IEnumerable<Image> imgs = productRepository.GetImages(p.ProductId);
if (imgs.Count() > 0) {
ViewData["MainImage"] = imgs.First();
ViewData["Images"] = imgs;
}
Brand brand = productRepository.GetBrand(p.ProductId);
ViewData["Brand"] = brand;
var categories = productRepository.GetCategories(p.ProductId, true);
ViewData["ProductCategories"] = categories;
return View("Details", p);
}
는 또한 내에서 Global.asax에 정의 된 경로는 다음과 같습니다
전체 동작 자체는 약 10 라인 길이 부디? 나는 완전히 난감한 처지입니다.
이 현상이 4 번 발생하는 것을 어떻게 알 수 있습니까? –
Firebug Net -> HTML 패널에 4 번 나열되어 있습니다. 나는 이것을 Burp Suite를 사용하여 두 번 확인했으며 실제로 페이지를 4 번 요청하고 있습니다. –
어, MVC와 관련이없는 또 다른 문제 일 수 있습니다. 4 가지 요청이 CSS/JS 파일 만위한 것이 아니라고 확신합니까? 이 같은 소리는 일부 비동기 요청 일 수도 있습니다. 각각 HTTP 200 요청입니까? HTTP 30x 리디렉션 일 수 있습니다. –