[英]How can I use ASP.NET to check if cookies are enabled without having a web page?
I am working on a desktop application that automates numerous websites and processes the returned data.我正在开发一个桌面应用程序,它可以自动化众多网站并处理返回的数据。 This application will be run on a server and the user will connect with remote desktop.
此应用程序将在服务器上运行,用户将连接到远程桌面。 The automation breaks when the server doesn't have cookies enabled, and instead of having the application stop working, I would like to check the server settings and tell the user why it isn't working.
当服务器没有启用 cookies 时,自动化中断,而不是让应用程序停止工作,我想检查服务器设置并告诉用户它为什么不工作。
To do this, I decided to create an ASP.NET Web Service.为此,我决定创建一个 ASP.NET Web 服务。 I figured that the web service could store the cookie and then try to access the data.
我认为 web 服务可以存储 cookie,然后尝试访问数据。 If the data is found, cookies are enabled and everything is good to go.
如果找到数据,cookies 已启用,go 一切正常。
I have read numerous tutorials like: http://www.csharphelp.com/2006/05/c-and-cookies/ that explain how to store and access cookies through ASP.NET.我已经阅读了许多教程,例如: http://www.csharphelp.com/2006/05/c-and-cookies/ ,它们解释了如何通过 Z9E0DA8438E1E38A1C30F4B76CE 存储和访问 cookies。 All of these however use a website.
然而,所有这些都使用一个网站。 The user clicks a button to generate a request and the web service can then send a response.
用户单击按钮生成请求,然后 web 服务可以发送响应。 I do not know how to make the process work without having a website, and I do not wish to automate a site of my own hosting as well.
我不知道如何在没有网站的情况下使该过程正常工作,并且我也不希望自动化我自己托管的网站。 I feel like I should be able to run a method on my webservice and it should work.
我觉得我应该能够在我的网络服务上运行一个方法并且它应该可以工作。
Does anyone know how this would be done?有谁知道如何做到这一点? I'd like a webservice that can handle request and response so I can create, store, and access cookies.
我想要一个可以处理请求和响应的 Web 服务,这样我就可以创建、存储和访问 cookies。 I thank you for any help that you may offer.
我感谢您提供的任何帮助。
Nathan Tornquist内森·托恩奎斯特
EDIT:编辑:
I am working on an database driven application.我正在开发一个数据库驱动的应用程序。 Some of the pieces are automated web sites, where the user puts in some data and then the program opens up a webBrowser control, fills in the forms, and then formats the resulting data.
其中一些是自动化的 web 站点,用户在其中输入一些数据,然后程序打开 webBrowser 控件,填写 forms,然后格式化生成的数据。 I would like to test if cookies are enabled based on the users security privileges so that I can disable automation and allow the user to fill in the data on their own if required.
我想测试是否根据用户的安全权限启用了 cookies,以便我可以禁用自动化并允许用户在需要时自行填写数据。 Most of the websites require cookies to log in.
大多数网站需要 cookies 才能登录。
This will be running on various versions of Windows Server.这将在 Windows 服务器的各种版本上运行。 By default I think the webBrowser control has the same security settings as Internet Explorer.
默认情况下,我认为 webBrowser 控件具有与 Internet Explorer 相同的安全设置。
var request = (HttpWebRequest)WebRequest.Create("http://stackoverflow.com/");
request.Method = "Head";
var response = (HttpWebResponse)request.GetResponse();
var usesCookies = !String.IsNullOrEmpty(response.Headers["Set-Cookie"]);
You can verify those keys on registry:您可以在注册表中验证这些键:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings\Zones HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings\Zones
HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings\Zones HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings\Zones
Under those keys, you may see some keys like 0, 1, 2, 3... Each one is a Zone configuration.在这些键下,您可能会看到一些键,例如 0、1、2、3……每个键都是一个区域配置。
Search for those entries in each Zone:在每个区域中搜索这些条目:
1A02 1A02
1A03 1A03
1A05 1A05
1A06 1A06
So you have to verify if those entries values are equals to 0.因此,您必须验证这些条目值是否等于 0。
See those links:查看这些链接:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.