.NET:将会话从 HttpWebRequest 传输到 WebBrowser 并获取完整的 JS、CSS 路径

发布于 2024-11-25 05:51:13 字数 1483 浏览 1 评论 0原文

我有以下问题。我正在使用 HttpWebRequest 类 发送发布请求。这个 post 请求实际上是 XML 文件的一部分,在传输之前使用 Base64 进行编码。发送 XML 文件,以便服务器可以在浏览器中创建格式化页面,然后具有适当证书的用户可以对该页面进行签名并保存在服务器上。我将其发送到 SSL 证书身份验证安全站点,这意味着我添加了一个客户端证书 HttpWebRequest.ClientCertificates 属性 到 HttpWebRequest 的实例。我还添加了 CookieContainer,因为该网站给出回应。

现在我得到了纯字符串(格式化文档)的响应。它实际上包含 html 响应的源代码。现在我使用 WebBrowser 显示响应给用户。问题是,该站点对 javascript 和 css 使用相对寻址,因此 WebBrowser 无法获取 javascript 库支持的样式和功能。

  1. 问题:所以我需要解决的第一个问题是,以某种方式向 WebBrowser 显示页面的 URL 地址(它实际上应该在哪里),以便 CSS 和 JS 文件可用。我尝试使用 WebBrowser.Url 属性,但没有成功。我只能说它必须指向用户经过身份验证后进入的第一页,因为所有 CSS 和 JS 文件都包含在文件夹 /GUI 中。也许它不起作用,因为必须在 WebBrowser 加载实际的 html 文件之前分配 URL 地址?
  2. 问题:因为用户需要签署文档(这是在他的私钥+小程序的帮助下完成的,从服务器运行),我需要从 HttpWebRequest 获得一个会话,我用它来发送帖子。这是因为发送到服务器并且现在作为格式化页面返回的帖子仅在此会话中有效。这意味着会话结束后它就会丢失。这就是为什么我必须以某种方式将会话从 HttpWebRequest 传输到 WebBrowser。

我正在使用 IED Visual Studio 2010、编程语言 C# 和 .NET FrameWork 3.5

提前感谢您的帮助!

I have the following problem. I am using HttpWebRequest Class to send a post request. This post request is actually a portion of a XML file, coded before the transmission with Base64. The XML file is sent, so that server can create a formatted page in the browser, which user with appropriate certificate can then sign and deposit on server. I am sending it to a SSL Certificate Authentication secured site so it means I have a client certificate added with the HttpWebRequest.ClientCertificates Property to an instance of HttpWebRequest. I also have CookieContainer added, because the site gives a response back.

Now I get the response back as plain string (formatted document). It actually contains source code of the html response. Now I use WebBrowser to display the response back to user. The problem is, that the site uses relative addressing for javascript and css, so the WebBrowser does not get the styles and functionality supported by javascript libraries.

  1. Problem: So the first problem that I need to solve it, is, to somehow show the WebBrowser the URL address of the page, where it should actually be, so that the CSS and JS files will be available. I tried that with WebBrowser.Url Property, but with no success. I can only say that it has to point to the first page, where user comes after authentication, because all the CSS and JS files are contained inside folder /GUI. Maybe it did not work, because the URL address has to be assigned before the WebBrowser is loaded with actual html file?
  2. Problem: Because the user needs to sign the document (that is done with the help of his private key + applet, that is ran from the server) I need to have a session from the HttpWebRequest, that I made to send the post. That is because the post that was sent to the server and is now returned as a formatted page is only valid in this session. It means it is lost after the session is over. That is why I have to transfer somehow the session from HttpWebRequest to WebBrowser.

I am using IED Visual Studio 2010, programming language C# and .NET FrameWork 3.5

Thanks in advance for any help!

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文