我想使用ImageResizer(来自ImageResize 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不提供"解决"选项.

推荐答案

问题是Controller类有一个名为HttpContext的公共属性(参见http://msdn.microsoft.com/en-us/library/system.web.mvc.controller.httpcontext.aspx).

这意味着,当您try 在控制器中没有任何限定的情况下使用它时,它将解析为本地属性,而不是System.Web.HttpContext.该属性的类型是HttpContextBase,它确实有一个Request属性,可以执行您想要的操作(不过请注意,它与您从System.Web.HttpContext获得的类不同.

Asp.net相关问答推荐

无法翻译 LINQ

asp.net 单选按钮分组

用户NT AUTHORITY\NETWORK SERVICE登录失败

防止 asp.net Web 表单中的跨站点请求伪造 (csrf) 攻击

HttpWebRequest 未通过凭据

无法加载文件或程序集'System.Web.WebPages.Razor,版本 = 3.0.0.0

如何使用 ASP.Net MVC 路由来路由图像?

如何使用自动生成的列隐藏 ASP.NET GridView 中的列?

如何在 ASP.NET 中仅在调试模式下执行代码

错误:无法在 Web 服务器上开始调试... ASP.NET 4.0

为 ASP.NET Core MVC 显示 404 Not Found 页面

缩小 ASP.Net MVC 应用程序的 HTML 输出

删除 HTML 或 ASPX 扩展

HttpContext.Current属性的跨线程使用及相关的东西

盒式磁带包与 MVC4 包

MVC4 - 当优化设置为 true 时Bundle 不起作用

ASP.NET 邮箱验证器正则表达式

如何将 DataTable 转换为类 Object?

如何创建代表 colored颜色 的随机十六进制字符串?

在没有等待 #2 的情况下调用异步方法