ASP.NET:MVC 4 - 简单登录使用Web服务作为数据存储 [英] ASP.NET: MVC 4 - Simple Login with Web Services as the data store

查看:106
本文介绍了ASP.NET:MVC 4 - 简单登录使用Web服务作为数据存储的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我建立一个 ASP.NET MVC 4 应用程序是表格验证。

I am building an ASP.NET MVC 4 application with Forms Authentication.

在我的帐户控制器我收到表格的用户名和密码。

In my Account controller I receive the username and password from the form.

A Web服务返回真/假如果用户名/密码是正确的。

A web service returns a true/false if the username/password are correct.

    [HttpPost]
    [AllowAnonymous]
    [ValidateAntiForgeryToken]
    public ActionResult Login(LoginModel model, string returnUrl)
    {
         bool isValid=MyWebService.ValidateLogin(model.Name,model.Pass);

          if(isValid){
            *** Here: Tell ASP.NET that model.Name is a logged in user
            ***       and to keep a cookie so that they stay logged in ???
            RedirectToAction(...);
           }
     }  

我希望利用尽可能多的ASP.NET基础设施,我可以的,但是要使用Web服务来获得登录权限。

I hope to leverage as much of the ASP.NET infrastructure as I can, but to use the Web Service to get the login right.

推荐答案

最COM prehensive的方式与框架级支持,这样做是为了实现自定义的的MembershipProvider 。这是pretty简单,并且有非常容易实现的功能。如果你想利用其他成员件,认证和授权的,这很可能是你的最佳途径。这里是你的步骤:

The most comprehensive way to do this with framework-level support is to implement a custom MembershipProvider. It's pretty straightforward, and there are very easy-to-implement features. If you want to leverage the other pieces of membership, authentication and authorization, this is likely your best route. Here are your steps:


  • 创建一个名为新类 YourMembershipProvider

  • 的MembershipProvider 继承并实现抽象方法

  • 仔细查看的方法和实施计,即那些:

    • 的ValidateUser

    • 的getUser

    • Create a new class called YourMembershipProvider
    • Inherit from MembershipProvider and implement the abstract methods
    • Look through the methods and implement the ones that count, namely:
      • ValidateUser
      • GetUser

      的getUser 将采取用户名并使用Web服务来查找你想要的任何相关成员详细信息跟踪。

      Your GetUser will take the username and use your web service to look up any relevant member details that you want to track.

      的ValidateUser 将是你打电话给你的Web服务。返回真正如果用户检查了。

      ValidateUser will be where you call your web service. Return true if the user checks out.

      最后,更新您的Web配置。在System.Web程序,你需要这样的:

      Finally, update your web config. In System.Web, you'll need something like this:

      <membership defaultProvider="YourMembershipProvider">
        <providers>
          <clear />
          <add name="YourMembershipProvider" type="YourNamespace.YourMembershipProvider" />
        </providers>
      </membership>
      

      因此​​,要回顾一下......实现类,线材你的web配置,使用该框架来处理其余部分。

      So, to recap...implement your class, wire up your web config, use the framework to handle the rest.

      干杯。

      这篇关于ASP.NET:MVC 4 - 简单登录使用Web服务作为数据存储的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆