ASP.NET MVC 2和FormsAuthentication的Web服务身份验证

时间:2010-08-19 08:49:47

标签: c# authentication asp.net-mvc-2

我正在使用ASP.NET MVC2,它从Web服务请求方法(我在Web服务中的所有DAO位置)。对于使用基本身份验证的Web服务。对于从asp.net到web-service的身份验证,我使用FormsAuthentication。为此我写了一个来自MembershipProvider的WebServiceMembershipProvider继承。在方法ValidateUser中,我连接到Web服务,如果验证成功 - 在cookie中保存票证使用FormsAuthentication.SetAuthCookie。

我的问题:验证后我必须存储用户名和密码:Cookie,会话还是其他? 我需要存储用户名和密码才能在Credentials中调用方法之前将其发送到Web服务,例如:

MyServiceSoapClient client = new MyServiceSoapClient();
client.ClientCredentials.UserName.UserName = this.username;
client.ClientCredentials.UserName.Password = this.password;
List<Product> products = client.GetProductList();

1 个答案:

答案 0 :(得分:1)

如果我正确理解了这个问题,那么你有一个网络应用程序,它可以在验证后调用需要用户名和密码进行函数调用的Web服务,这也是一个函数调用。

在您的WebService类(WebServiceMembershipProvider)中,您从MembershipProvider继承并调用MembershipProvider.ValidateUser

If you are talking about storing more information then just that in FormsAuthentication.SetAuthCookie, then this is the answer you are probably looking for.

Other wise this has a lot of example code for working with Forms Authentication in Webservices that might help you.