简体   繁体   English

在没有 web 页面的情况下,如何使用 ASP.NET 检查 cookies 是否已启用?

[英]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:查看这些链接:

ms kb毫秒 kb
question问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何检查asp.net中是否启用了cookie? - How to check if cookies are enabled or disabled in asp.net? 如何检查网页是否已通过ASP.Net上的特定IP地址访问? - How can i check if the web page is already accessed in particular IP Address on ASP.Net? 我如何在没有登录表单的情况下将摘要身份验证与asp.net Web API和angular js一起使用? - How can I use digest auth with asp.net web api and angular js without a login form? ASP.NET网页出现问题 - Having issues with ASP.NET web page 如何在ASP.NET中加密和解密我的Cookie - How can i encrypt and decrypt my Cookies in ASP.NET 如何在没有母版页的情况下在 asp.net 中打印页面并更改页面的配色方案? - How can i print a page in asp.net without master page and to change color schemes of the page? 更新Cookie而不刷新页面(Asp.net) - Update cookies without refreshing page (Asp.net) 网页中可以使用多个ASP.NET按钮吗? - Can I use more than One ASP.NET Button in a web page? 查询CRM Online时如何配置ASP.NET网页以使用wsHttpBinding? - How do I configure an ASP.NET web page to use wsHttpBinding when querying CRM Online? 如何将 AccessTokens 存储到 Cookies 并使用它们为 Asp.net web 应用程序(非 MVC)调用图 API - How Store AccessTokens to Cookies and use them to call Graph API for Asp.net web application (non MVC)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM