Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/wcf/4.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/silverlight/4.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
Wcf 如何在自定义Web服务中对用户进行表单身份验证?_Wcf_Silverlight_Security_Forms Authentication_Membership Provider - Fatal编程技术网

Wcf 如何在自定义Web服务中对用户进行表单身份验证?

Wcf 如何在自定义Web服务中对用户进行表单身份验证?,wcf,silverlight,security,forms-authentication,membership-provider,Wcf,Silverlight,Security,Forms Authentication,Membership Provider,我正在将silverlight站点集成到现有的应用程序中,并尝试让登录功能正常工作。Silverlight应用程序需要有自己的登录页面,并且登录需要利用现有的ASP.NET表单身份验证。作为登录过程的一部分,我们正在调用一些外部代码,因此使用System.Web.ApplicationServices.AuthenticationService公开的可编写脚本的方法是不可取的。我尝试使用FormsAuthentication.Authentication来执行此操作,但无效。有人对如何解决这个问

我正在将silverlight站点集成到现有的应用程序中,并尝试让登录功能正常工作。Silverlight应用程序需要有自己的登录页面,并且登录需要利用现有的ASP.NET表单身份验证。作为登录过程的一部分,我们正在调用一些外部代码,因此使用System.Web.ApplicationServices.AuthenticationService公开的可编写脚本的方法是不可取的。我尝试使用FormsAuthentication.Authentication来执行此操作,但无效。有人对如何解决这个问题有什么想法吗?

听起来好像您需要创建一个包装器WebDevice来实现表单身份验证支持

这是我所做的,例如,我创建了一个WCF服务,它具有以下接口,由我的Silverlight客户端引用:

[ServiceContract]
    public interface IAuthenticationService
    {
        [OperationContract()]
        string Login(string username, string password, bool isPersistent);
        [OperationContract()]
        bool Logout();
        [OperationContract()]
        string IsLoggedIn();     
    }
然后,在我的实现中,您可以调用自定义代码,还可以使用表单身份验证api,例如登录,您可以:

try
            {
                //Call you external code here
                //Then use the membership provider to authenticate
                if (Membership.ValidateUser(username, password))
                {

                    FormsAuthentication.SetAuthCookie(username, isPersistent);

                }
            }
            catch (Exception ex)
            {
                Logging.LogException("Error in Login", ex);
            }
同样,您也不需要在服务实现中的类定义上方包含以下属性,即可启用asp.net compat,从而访问HttpContext:

 [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required)]

解决办法很简单。只需创建一个调用自定义代码的自定义成员资格提供程序。有关更多信息,请参阅。在和上还有完整的样品。最后,对于内置的成员资格提供商,它显示了此web服务的具体位置?这看起来非常像的重复:问题类似,但我无法使用这些解决方案,因为我需要在登录之前打一个外部电话。