如何从 WPF 应用程序向默认浏览器发送 Web 请求?

发布于 2024-10-25 12:56:53 字数 390 浏览 2 评论 0原文

我正在开发一个 WPF 应用程序,它是网站的桌面对应部分。

这个想法是应用程序应该具有与网站相同的功能,但对于应用程序的第一个版本,并非所有功能都可用,因此我想在尚不可用的功能上添加一个链接,希望当用户单击该链接时,我想将他们带到该网站,即该功能的页面。

到目前为止,我可以毫无困难地做到这一点,使用 shell 命令我可以打开默认浏览器并将请求发送到网站上我需要的资源。

现在,棘手的部分是我想使用用户在桌面应用程序中使用的凭据来对网站进行身份验证,因此用户不必再次进行身份验证,我正在考虑发送在标头中加密的凭据,但是我不知道如何做到这一点,如何将标头从我的应用程序发送到网络浏览器。

关于如何做到这一点有什么想法吗?

顺便说一句,该网站正在使用表单身份验证。

谢谢。

I'm working in a WPF application which is the desktop counter-part of a website.

The idea is that the application should have the same functionalities that the website has, but for the first release of the application not all features would be available, because of this I want to put a link on the features that are not available yet and hopefully when the user click on that link I want to take them to the website, to the page for that functionality.

So far, I can do this with no trouble, using the shell command I can open the default browser and send the request to the resource I need on the website.

Now, the tricky part is that I want to use the credentials that the user used in the desktop application to authenticate with the website, so the user doesn't have to authenticate again, I was thinking in sending the credentials encrypted in a header but I don't know how can I do this, how can I send the header to the web browser from my application.

Any idea on how to do this?

BTW the website is using Forms Authentication.

Thanks.

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

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

发布评论

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

评论(1

水水月牙 2024-11-01 12:56:53

您可以尝试将表单身份验证 cookie 作为网络请求的一部分传递。

Uri uri = new Uri("http://services.mysite.com/document/documentservice.svc");
HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(uri);       

HttpCookie cookie = HttpContext.Current.Request.Cookies[FormsAuthentication.FormsCookieName];
Cookie authenticationCookie = new Cookie(FormsAuthentication.FormsCookieName, cookie.Value, cookie.Path, HttpContext.Current.Request.Url.Authority);

webRequest.CookieContainer = new CookieContainer();
webRequest.CookieContainer.Add(authenticationCookie);
WebResponse myResponse = webRequest.GetResponse();
Stream stream = myResponse.GetResponseStream();

尝试链接

You could try passing your forms authentication cookie as part of the webrequest.

Uri uri = new Uri("http://services.mysite.com/document/documentservice.svc");
HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(uri);       

HttpCookie cookie = HttpContext.Current.Request.Cookies[FormsAuthentication.FormsCookieName];
Cookie authenticationCookie = new Cookie(FormsAuthentication.FormsCookieName, cookie.Value, cookie.Path, HttpContext.Current.Request.Url.Authority);

webRequest.CookieContainer = new CookieContainer();
webRequest.CookieContainer.Add(authenticationCookie);
WebResponse myResponse = webRequest.GetResponse();
Stream stream = myResponse.GetResponseStream();

try this link

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