Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/317.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何从WPF应用程序向默认浏览器发送webrequest?_C#_Wpf_Authentication_Httpwebrequest_Forms Authentication - Fatal编程技术网

C# 如何从WPF应用程序向默认浏览器发送webrequest?

C# 如何从WPF应用程序向默认浏览器发送webrequest?,c#,wpf,authentication,httpwebrequest,forms-authentication,C#,Wpf,Authentication,Httpwebrequest,Forms Authentication,我在一个WPF应用程序中工作,它是网站的桌面计数器部分 我们的想法是,应用程序应该具有与网站相同的功能,但对于应用程序的第一个版本,并非所有功能都可用,因此我想在尚未可用的功能上添加一个链接,希望当用户单击该链接时,我想将其带到网站,转到页面以获取该功能 到目前为止,我可以毫不费力地做到这一点,使用shell命令,我可以打开默认浏览器并将请求发送到网站上我需要的资源 现在,棘手的部分是,我想使用用户在桌面应用程序中使用的凭据对网站进行身份验证,这样用户就不必再次进行身份验证,我正在考虑发送在标题

我在一个WPF应用程序中工作,它是网站的桌面计数器部分

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

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

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

你知道怎么做吗

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


谢谢。

您可以尝试将表单验证cookie作为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();

尝试链接

如果您在WPF应用程序中浏览网站,这没关系,但是如何将cookie传递到默认浏览器?