.NET Framework 4 客户端配置文件 +系统.Web.dll?

发布于 2024-10-16 21:58:48 字数 290 浏览 8 评论 0原文

我目前正在开发 .NET 4 Client Profile 的应用程序,因为该版本将通过 Windows 更新出现在大多数家庭计算机上。

但是,我无法添加对 System.Web.dll 的引用,因为该版本中不存在它 - 我该怎么办?

将 System.Web.dll 与我的应用程序一起部署是一个好主意,还是不起作用?我确实需要 HTTP 连接等,所以我无法修改我的应用程序作为解决方法。将我的应用程序定位到 .NET 4(无客户端配置文件)可能是一种可能性,还是在仅具有客户端配置文件的计算机上不起作用?

I'm currently developing an application for .NET 4 Client Profile, as this is the version that will be present on most home computers through Windows Update.

However, I cannot add a reference to System.Web.dll as it does not exist in this version - what should I do?

Is it a good idea to deploy System.Web.dll along with my application, or won't that work? I really need HTTP connections and all, so I cannot modify my application as a workaround. Is targeting my application to .NET 4 (no client profile) perhaps a possibility or will that just not work on computers with only the Client Profile?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

旧情别恋 2024-10-23 21:58:48

NET 4 客户端配置文件,因为这是
大多数版本都会出现
通过 Windows 更新的家庭计算机

事实并非如此。默认情况下,.NET 4(无论是否为客户端配置文件)当前不存在于任何 Windows 10 之前的安装中。例如,Windows 7 附带 .NET 3.5 SP1,而不是 .NET 4.0。可能有 Windows 更新,但它是可选的。

因此,您不妨以完整的 .NET 4 框架为目标。

可以找到操作系统和 .NET Framework 版本之间的链接 这里。复选标记表示该版本是开箱即用的,加号表示可以安装。

另请注意,4.5、4.6 和 4.6.1 都是就地更新,这意味着具有其中任何一个的系统也被视为具有 4.0。

NET 4 Client Profile, as this is the
version that will be present on most
home computers through Windows Update

Not really. .NET 4 (client profile or not) currently isn't present on any pre-Windows 10 installation by default. For example, Windows 7 comes with .NET 3.5 SP1, not .NET 4.0. There may be a windows update, but it is optional.

Therefore, you might as well target the full .NET 4 framework.

The link between operating systems and .NET framework versions can be found here. The checkmarks indicate that a version is available out of the box, plus sign means it can be installed.

Also note that 4.5, 4.6 and 4.6.1 are all in-place updates, meaning that a system with any of those is also considered to have 4.0.

难得心□动 2024-10-23 21:58:48

如果您的目标是 .NET 4.0 而不是 .NET 4.0 客户端配置文件,则应将其添加为 先决条件。这将允许在您安装应用程序时安装它。

如果您运行 .NET 4.0 Client Profile,您仍然可以使用套接字,它们位于System.Net中。当满足以下条件时,您需要System.Web

System.Web 命名空间提供
类和接口使得
浏览器-服务器通信。这
命名空间包括 HttpRequest
类,它提供了广泛的
有关当前 HTTP 的信息
要求; HttpResponse 类,其中
管理到客户端的 HTTP 输出;和
HttpServerUtility 类,其中
提供对服务器端的访问
实用程序和流程。系统.Web
还包括 cookie 类
操作、文件传输、异常
信息,以及输出缓存控制。

If you are targeting .NET 4.0 and not .NET 4.0 Client Profile you should add that as a prerequisite. This will allow it to be installed when you install your application.

You can still use Sockets if you run .NET 4.0 Client Profile, they are located in System.Net. You only want System.Web when the following applies:

The System.Web namespace supplies
classes and interfaces that enable
browser-server communication. This
namespace includes the HttpRequest
class, which provides extensive
information about the current HTTP
request; the HttpResponse class, which
manages HTTP output to the client; and
the HttpServerUtility class, which
provides access to server-side
utilities and processes. System.Web
also includes classes for cookie
manipulation, file transfer, exception
information, and output cache control.

青芜 2024-10-23 21:58:48

如果您只想使用 HttpWebRequest,它可以在 .Net 4 的客户端配置文件中找到。

这是一个您可以尝试的示例,只需使用 .Net 4 客户端配置文件创建一个新的控制台应用程序并将其粘贴到 Program.cs 中...

using System;
using System.IO;
using System.Net;

namespace ConsoleApplication3
{
    class Program
    {
        static void Main(string[] args)
        {
            var request = WebRequest.Create("http://google.com");
            var response = request.GetResponse();
            using (var s = response.GetResponseStream())
            using( var sr = new StreamReader(s))
            {
                Console.Write(sr.ReadToEnd());
            }

            Console.ReadKey();
        }
    }
}

您在评论之一中询问了 HttpCookieCollection。 HttpWebRequest 似乎使用 CookieContainer 来存储 cookie。

If you are just wanting to use the HttpWebRequest, it is available in the client profile for .Net 4.

Here's an example that you can try, just create a new console app using the .Net 4 Client Profile and paste this into Program.cs...

using System;
using System.IO;
using System.Net;

namespace ConsoleApplication3
{
    class Program
    {
        static void Main(string[] args)
        {
            var request = WebRequest.Create("http://google.com");
            var response = request.GetResponse();
            using (var s = response.GetResponseStream())
            using( var sr = new StreamReader(s))
            {
                Console.Write(sr.ReadToEnd());
            }

            Console.ReadKey();
        }
    }
}

You asked about HttpCookieCollection in one of your comments. It seems that HttpWebRequest uses a CookieContainer to store the cookies.

故人的歌 2024-10-23 21:58:48

即使您将 System.Web.dll 的副本部署到客户端也无法解决问题。问题是:您无法从为 .NET 4 客户端配置文件编译的程序集链接到为 .NET 4 配置文件(不是客户端)编译的程序集。唯一的解决方案是将您的程序集定位到非客户配置文件。

有关 .NET Framework 客户端配置文件的 MSDN 页面

Even if you deploy the copy of the System.Web.dll to the client that won't solve the problem. And the problem is: you can't link to the assemblies compiled for .NET 4 profile (not client) from the assembly that compiled for .NET 4 Client profile. The only solution is to target your assembly to the not client profile.

The MSDN Page about .NET Framework Client Profile.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文