Nic*_*ick 34 c# asp.net asp.net-mvc httpcontext asp.net-mvc-4
我想使用ImageResizer(来自ImageResizing dot net).我通过NuGet为MVC安装了ImageResizer.但是当我从示例中使用以下代码时:
//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();
}
foreach中的"HttpContext.Current.Request.Files.Keys"是不是正在解决?我的用法正确,Visual Studio不提供"Resolve"选项.
小智 104
尝试使用前缀 System.Web.
如果我尝试System.Web.HttpContext.Current,那么Current就在那里,但如果我尝试HttpContext.Current,那么它就不会识别'Current'.System.Web我的使用声明确实存在,但我仍然需要指定它才能访问"当前".
Chr*_*ris 60
问题是Controller该类有一个名为的公共属性HttpContext(请参阅http://msdn.microsoft.com/en-us/library/system.web.mvc.controller.httpcontext.aspx).
这意味着当您尝试在控制器中没有任何限定条件的情况下使用它时,它会解析为本地属性而不是System.Web.HttpContext.属性的类型HttpContextBase确实具有Request可以执行所需操作的属性(但请注意,它与您获得的属性不同System.Web.HttpContext.
| 归档时间: | 
 | 
| 查看次数: | 43229 次 | 
| 最近记录: |