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得到的相同的类。 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
推荐文章
站长推荐
- 如何在ASP.Net中设置TextBox的默认按钮?
- asp.net – ModalPopupExtender和验证问题
- asp.net – 将MemoryCache与HostFileChangeMonit
- asp.net core 系列 9 三种运行环境和IIS发布
- asp.net – 即使在ssl上,在ViewState中存储信用卡
- asp.net – applicationSettings和Web.config
- 使用System.Net.Mail中的SMTP发送邮件(带附件)
- ASP.NET表单身份验证 – 在调试时使用测试帐户自
- asp.net-mvc – 使用StructureMap / ASP.MVC / V
- asp.net – Web API外部承载未经授权
热点阅读