C# - 我不能引用 HttpPostedFileBase
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1911151/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
C# - I cannot reference HttpPostedFileBase
提问by Teddy
I am using MVC .NET in a distributed environment with CSLA and I canreference HttpPostedFileBase from one of my web layers (eg Website.MVC), but I cannotreference HttpPostedFileBase from a separate layer (lets call it OtherLayer.Web).
我在具有 CSLA 的分布式环境中使用 MVC .NET,我可以从我的一个 web 层(例如 Website.MVC)引用 HttpPostedFileBase ,但我不能从单独的层(我们称之为 OtherLayer.Web)引用 HttpPostedFileBase。
Any idea on what I need to do to be able to call HttpPostedFileBase ? I am able to use HttpPostedFile in both layers - should I just use this instead?
知道我需要做什么才能调用 HttpPostedFileBase 吗?我可以在两个层中使用 HttpPostedFile - 我应该使用它吗?
The assembly references are basically the same - in Website.MVC I have:
程序集引用基本相同 - 在 Website.MVC 我有:
namespace Website.Mvc.Controllers
{
using System;
using System.Collections;
using System.Collections.Generic;
using System.Web.Mvc;
using System.Web;
using System.IO;
using PetOrganizer.Mvc.Helpers;
using TrupanionPetInsurance.Web;
Whereas in my other layer i have:
而在我的另一层,我有:
namespace OtherLayer.Web
{
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Data;
using System.Data.SqlClient;
using System.IO;
using System.Net.Mail;
using System.Text;
using System.Text.RegularExpressions;
using System.Web;
using System.Web.Mvc;
using System.Web.Security;
using System.Xml;
using System.Xml.Serialization;
using Csla;
using iTextSharp.text;
using iTextSharp.text.pdf;
using TruDat.BusinessLayer;
using TruDat.BusinessLayer.Billing;
using TruDat.BusinessLayer.Data;
using TruDat.BusinessLayer.Utility;
using TrupanionPetInsurance.Web.EmailTemplateParser;
using TruDat.BusinessLayer.DataServices;
采纳答案by Andrew Hare
Make sure your project references the System.Web.Abstractions
assembly which contains the HttpPostedFileBase
type.
确保您的项目引用System.Web.Abstractions
包含该HttpPostedFileBase
类型的程序集。
As confusing as it may seem, the HttpPostedFile
type lives in a separate assembly (System.Web
) but the same exact namespace.
尽管看起来令人困惑,但该HttpPostedFile
类型存在于单独的程序集 ( System.Web
) 中,但具有完全相同的命名空间。
It is important to remember that the namespaces can span assemblies and the name of an assembly does not necessarily dictate the namespace of the types contained in it. There is no System.Web.Abstractions
namespacesimply two assemblies that contain types in the System.Web
namespace.
重要的是要记住命名空间可以跨越程序集,程序集的名称不一定决定其中包含的类型的命名空间。没有System.Web.Abstractions
命名空间,只有两个程序集在System.Web
命名空间中包含类型。
Once you have referenced both assemblies you can reference both types by their unqualified names with this single using statement:
一旦您引用了两个程序集,您就可以使用以下单个 using 语句通过它们的非限定名称来引用这两种类型:
using System.Web;
回答by Loaderon
Make sure your project references the System.Web.Abstractions assembly which contains the HttpPostedFileBase type.
确保您的项目引用包含 HttpPostedFileBase 类型的 System.Web.Abstractions 程序集。
Thanks, Andrew Hare, that did the trick, yet I believe that from .Net 4.0 and so on, System.Web.Abstractions is deprecated, and you should add reference to System.web instead.
谢谢,Andrew Hare,这成功了,但我相信从 .Net 4.0 等开始,System.Web.Abstractions 已被弃用,您应该添加对 System.web 的引用。
In my case, that was the ultimate solution, after that
就我而言,这是最终的解决方案,之后
using System.Web;
worked, and therefore, HttpPostedFileBase was recognized.
工作,因此, HttpPostedFileBase 被识别。
Thanks.
谢谢。