我正在开发一个调用 ASP.NET 2.0 网站的 .NET 2.0 winforms 应用程序。该网站使用表单身份验证进行身份验证。在 web.config 中启用了身份验证服务,并且我做了一些 实验以确认我可以通过 JSON 访问该服务。
我的问题是:是否有任何内置代码可以在纯.NET环境(不是ASP.NET)中使用System.Web.Extensions Web服务(authenticationService、profileService等)?我可以找到使用 Silverlight 和后来的 WCF 服务的示例,但在客户端和服务器上都找不到 2.0 环境中的任何内容。将身份验证服务添加为 Web 服务似乎是合乎逻辑的方法,但我永远无法让它指向我的开发服务器 - 我想这可能是一个单独的问题。
如果我必须在较低级别管理 AJAX 请求和响应,这当然是可行的,但如果某些东西已经用于此目的,那么它肯定会更容易并且更不容易出错。
I am working on a .NET 2.0 winforms application that calls an ASP.NET 2.0 website. The website is authenticated using forms authentication. The authentication service is enabled in the web.config, and I have done some experiments to confirm that I can access the service via JSON.
Here is my question: is there any built-in code to consume the System.Web.Extensions web services (authenticationService, profileService, etc.) in a purely .NET environment (not ASP.NET)? I can find examples using Silverlight and the later WCF services, but not anything in a 2.0 environment on both client and server. Adding the authentication service as a web service seems like the logical approach, but I could never get it to work pointing to my development server - I suppose that could be a separate question.
If I have to manage the AJAX request and response at a lower level, it's certainly doable, but if something were already intended for this purpose it would certainly be easier and less error-prone.
发布评论
评论(2)
我从来没有得到这个问题的答案,但最终在 本教程。简短的回答是肯定的,我必须在相当低的级别上管理 AJAX 请求/响应。假设您有需要进行身份验证的用户名和密码,您首先需要为其获取身份验证 cookie。我使用 Newtonsoft 的 Json.NET 库 进行 JSON 序列化和反序列化,但是你可以使用任何东西。
接下来,将 cookie 添加到后续请求中。就我而言,这意味着将 cookie 添加到我正在使用的 Web 服务代理的 CookieContainer 中。
I never got an answer for this, but eventually figured it out with the help of this tutorial. The short answer was yes, I had to manage the AJAX request/response at a fairly low level. Assuming you have a username and password you need to authenticate with, you first need to get an authentication cookie for it. I used the Json.NET library from Newtonsoft for the JSON serialization and deserialization, but you could use anything.
Next, add the cookie to subsequent requests. In my case, that meant adding the cookie to the CookieContainer of the web service proxy I was using.
我无法让authenticationService 工作。当我尝试从 winforms 应用程序调用 Authentication_JSON_AppService.axd 时,我不断收到 404 错误。所以我最终编写了自己的 JSON 身份验证 WebMethod。
抱歉,这不是 C#,我的项目是 VB.NET。我使用这个 http://progtutorials.tripod.com/Authen.htm 作为参考。
确保 web.config 中的匿名用户可以访问您的身份验证 WebService。
I was not able to get the authenticationService working. I kept getting 404 errors when I tried to call Authentication_JSON_AppService.axd from my winforms application. So I ended up writing my own JSON authentication WebMethod.
Sorry it's not C#, my project is VB.NET. I used this http://progtutorials.tripod.com/Authen.htm as a reference.
Be sure to make your authentication WebService accessible to anonymous users in your web.config.