【问题标题】:Web-service authentication from ASP.NET MVC 2 and FormsAuthentication来自 ASP.NET MVC 2 和 FormsAuthentication 的 Web 服务身份验证
【发布时间】:2011-04-01 00:15:38
【问题描述】:

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

我的问题:验证后我必须在哪里存储用户名和密码:Cookies、Session 还是其他? 在调用凭据中的方法之前,我需要存储用户名和密码以将其发送到 Web 服务,例如:

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

【问题讨论】:

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


    【解决方案1】:

    如果我正确理解了这个问题,您有一个 Web 应用程序调用了一个 Web 服务,该 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.

    【讨论】:

    • 我知道这个问题很老了,但我需要代表我自己的一个赏金。我希望至少这对投票的人有用。
    • 我们使用在 FormsAuth cookie 中存储附加信息的方法,通过将其序列化和反序列化进出 UserData。它对我们很有效,但我对将用户密码存储在其中(尽管它是加密的)有所保留。
    猜你喜欢
    • 2016-06-10
    • 2016-07-17
    • 1970-01-01
    • 1970-01-01
    • 2017-08-15
    • 2015-05-21
    • 2015-09-17
    • 2014-03-20
    • 1970-01-01
    相关资源
    最近更新 更多