如何在自定义 Web 服务中通过表单对用户进行身份验证?
我正在努力将 silverlight 站点集成到我们现有的应用程序中,并尝试让登录功能正常工作。 Silverlight应用程序需要有自己的登录页面,并且登录需要利用现有的ASP.NET表单身份验证。 作为登录过程的一部分,我们正在调用一些外部代码,因此不能选择使用 System.Web.ApplicationServices.AuthenticationService 公开的可编写脚本的方法。 我尝试使用 FormsAuthentication.Authenticate 来执行此操作,但它不起作用。 有人对如何解决这个问题有任何想法吗?
I am working on integrating a silverlight site into our existing application and am trying to get the login functionality working. The Silverlight application needs to have it's own login page, and the login needs to utilize the existing ASP.NET forms authentication. As part of the login procedure, we are calling some external code, so using the scriptable methods that System.Web.ApplicationServices.AuthenticationService exposes is not an option. I tried to use FormsAuthentication.Authenticate to do this, but it didn't work. Does anyone have any ideas on how to get around this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
听起来好像您需要创建一个包装器 Web 服务来实现表单身份验证支持。
这是我所做的事情,例如我创建了一个具有以下接口的 WCF 服务,该接口由我的 Silverlight 客户端引用:
然后在我的实现中,您可以调用自定义代码并使用表单身份验证 api,例如您可以登录:
此外,您不需要在服务实现中的类定义上方包含以下属性,即可启用 asp.net compat,这将使您能够访问 HttpContext:
It sounds as though you need to create a wrapper websevice which can implement the forms authentication support.
This is something I've done so for example I've created a WCF service with the following interface which is referenced by my Silverlight client:
and then in my implementation you can call custom code and also use the forms authentication api, for example to login you could have:
Also not you need to include the following attribute above you class definition in your service implementation to have asp.net compat enabled which will give you access to the HttpContext:
解决方案很简单。 只需创建一个调用您的自定义代码的自定义会员资格提供程序即可。 有关详细信息,请参阅这篇关于 MSDN 库的文章。 还有 15 秒 和 ASP.NET 网站上的演练视频。 最后,看来微软已经发布了源代码内置会员提供程序
The solution is simple. Just create a custom membership provider that calls your custom code. See this article on MSDN library for more information. There are also full samples available on 15 seconds and a walkthrough video on the ASP.NET website. Finally, it appears Microsoft has released the source for the built-in Membership Provider