ImageResizer (ImageResizing dot net에서)를 사용하고 싶습니다. NuGet을 통해 MVC 용 ImageResizer를 설치했습니다. 하지만 예제에서 다음 코드를 사용하여 갈 때 :HttpContext.Current가 MVC 4 프로젝트에서 해결되지 않음
//Loop through each uploaded file
foreach (string fileKey in HttpContext.Current.Request.Files.Keys)
{
HttpPostedFile file = HttpContext.Current.Request.Files[fileKey];
if (file.ContentLength <= 0) continue; //Skip unused file controls.
//The resizing settings can specify any of 30 commands.. See http://imageresizing.net for details.
//Destination paths can have variables like <guid> and <ext>, or
//even a santizied version of the original filename, like <filename:A-Za-z0-9>
ImageResizer.ImageJob i = new ImageResizer.ImageJob(file, "~/uploads/<guid>.<ext>", new ImageResizer.ResizeSettings(
"width=2000;height=2000;format=jpg;mode=max"));
i.CreateParentDirectory = true; //Auto-create the uploads directory.
i.Build();
}
는 "HttpContext.Current.Request.Files.Keys을"foreach 문에서 해결되지 않는 이유는 무엇입니까? 내 사용법이 정확하고 Visual Studio는 "해결"옵션을 제공하지 않습니다. 내가 System.Web.HttpContext.Current
을하려고하면
HttpContext.Current가 아무 것도 설정되어 있지 않습니까 ("해결"됩니까?), 아니면 HttpContext.Current.Request.Files.Keys 만 표시되지 않습니까? 컨트롤러 또는 다른 클래스의 코드입니까? 이것이 다른 클래스의 메소드에서 온 것이라면 HttpContext.Current를 어떻게 든 전달해야합니다. 호출하는 메서드의 매개 변수로 사용하거나 메서드를 호출하기 전에이 값을 사용하는 public 멤버 (HttpContext 형식)가 있어야합니다. – Floremin
HttpContext.Current가 응용 프로그램에서 전역이 아닙니다. 요청을 처리하는 동작 및보기에 설정되지만 요청주기 (모델, 유틸리티 클래스 등) 외부에는 존재하지 않습니다. 거기에 필요하다면, 당신은 @Floremin이 말했듯이, 그것이 존재하는 동작이나 뷰로부터 전달해야합니다. –
OK - 예, 내 컨트롤러의 작업 내에 있습니다. HttpContext는 해석하지만 Current는 분석하지 않습니다. 정적 Current없이 HttpContext.Request.Files 찾을 및이 잘 작동하는 것. 왜 정적 전류가 거기에 없으며 컨트롤러 "컨텍스트"에서 액세스 할 수 없는지 확실하지 않습니까? 잘하면 정적을 사용하지 않는 것이 "누락"되지 않았기 바랍니다. 감사! – Nick