加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

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

发布时间:2020-12-15 18:55:55 所属栏目:asp.Net 来源:网络整理
导读:我想使用ImageResizer(从ImageResizing点网)。我通过NuGet为MVC安装ImageResizer。但是当我去使用下面的代码从示例: //Loop through each uploaded file foreach (string fileKey in HttpContext.Current.Request.Files.Keys) { HttpPostedFile file = Http
我想使用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得到的相同的类。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读