asp.net – HttpContext.Current不解析在MVC 4项目

我想使用ImageResizer(从ImageResizing点网)。我通过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”选项。

解决方法

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

这意味着,当您尝试在控制器中使用它而没有任何限定时,它将解析为本地属性,而不是System.Web.HttpContext。属性的类型是HttpContextBase,它有一个Request属性,它会做你想要的(但请注意,它不是你从System.Web.HttpContext得到的相同的类。

相关文章

### 创建一个gRPC服务项目(grpc服务端)和一个 webapi项目(...
一、SiganlR 使用的协议类型 1.websocket即时通讯协议 2.Ser...
.Net 6 WebApi 项目 在Linux系统上 打包成Docker镜像,发布为...
一、 PD简介PowerDesigner 是一个集所有现代建模技术于一身的...
一、存储过程 存储过程就像数据库中运行的方法(函数) 优点:...
一、Ueditor的下载 1、百度编辑器下载地址:http://ueditor....