使用 rest api 和 angularjs 登录 asp.net

Login in asp.net using rest api and angularjs

本文关键字:登录 asp net angularjs rest api 使用      更新时间:2023-09-26

我使用 AngularJS 和 REST API 在 ASP.NET 中创建了一个登录页面,但我不知道如何创建?

如何使用 AngularJS 和 REST API 以及自动生成的令牌在 ASP.NET 中执行登录操作。

设计形式如下

  <div class="form-box" id="login-box">
        <div class="header">Sign In</div>
        <form>
            <div class="body bg-gray">
                <div class="form-group">
                    <input type="text" name="userid" ng-model="login.user_user" class="form-control" placeholder="User ID"/>
                </div>
                <div class="form-group">
                    <input type="password" name="password" ng-model="login.user_pass" class="form-control" placeholder="Password"/>
                </div>          
                <div class="form-group">
                    <input type="checkbox" name="remember_me"/> Remember me
                </div>
            </div>
            <div class="footer">                                                               
                <button type="submit" class="btn bg-olive btn-block" ng-click="doLogin(login)">Sign me in</button>  

            </div>
        </form>

    </div>

在控制器中

//Controller to login
app.controller('login', function ($scope) {
  //initially set those objects to null to avoid undefined error
  $scope.doLogin               = {};
  logdata                      = {};

  $scope.doLogin  = function (logdata) {
                  $http.post('urltopost').then(function(result){
                        if(result.data.flag==1)
                        {
                            window.location = "home.html";
                        }
                        else
                        {
                          alert('Wrong username and password!');
                        }
                  });

  };

});