Rupesh N

Rupesh N

  • NA
  • 380
  • 46.6k

Error: 2nd time enter login page will Success.

Aug 1 2018 10:43 PM
Hi. My name is Rupesh.
 
Actully, i am creating login page with help of angularjs and webmethod.
 
problem is, first enter login details not connect .
 
but, second time same details enter will connected.
 
so, please any one tell me where is the problem.
 
it's very urgent guys. my job issue. please tell me anyone.
 
Thank you.
 
Angularjs:
  1. <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.9/angular.min.js"></script>  
  2. var app = angular.module('myApp', []);  
  3. app.controller('myController'function ($http, $scope, $window) {  
  4. $scope.savedata = function () {  
  5. debugger  
  6. var post = $http({  
  7. method: "post",  
  8. url: "login.aspx/insertpassword",  
  9. dataType: 'json',  
  10. data: { Username: $scope.username, Password: $scope.password },  
  11. headers: { "ContentType""application/json" }  
  12. });  
  13. post.success(function (data, status) {  
  14. $window.alert(data.d);  
  15. if (data.d == 'ok')  
  16. {  
  17. window.location = 'http://localhost:12035/user/dashboard.aspx';  
  18. }  
  19. else  
  20. {  
  21. $window.alert(data.d);  
  22. }  
  23. });  
  24. post.error(function (data, status) {  
  25. $window.alert(data.d);  
  26. });  
  27. }  
  28. });  
Html code:
  1. <body ng-app="myApp" ng-controller="myController">  
  2. <div class="form-group">  
  3. <label class="form-label">Email address</label>  
  4. <input type="email" class="form-control" id="exampleInputEmail1" ng-model="username" aria-describedby="emailHelp" placeholder="Enter email" />  
  5. </div>  
  6. <div class="form-group">  
  7. <label class="form-label">  
  8. Password  
  9. <a href="./forgot-password.html" class="float-right small">I forgot password</a>  
  10. </label>  
  11. <input type="password" class="form-control" id="exampleInputPassword1" ng-model="password" placeholder="Password" />  
  12. </div>  
  13. <div class="form-footer">  
  14. <button type="submit" class="btn btn-primary btn-block" ng-click="savedata()">Sign in</button>  
  15. </div>  
  16. </body>  
Webmethod:
  1. public static string insertpassword(string Username,string Password)  
  2. {  
  3. using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["dbconnect"].ConnectionString))  
  4. {  
  5. SqlCommand cmd = new SqlCommand("Logincheck", con);  
  6. cmd.CommandType = CommandType.StoredProcedure;  
  7. cmd.Parameters.AddWithValue("@UserName", Username);  
  8. cmd.Parameters.AddWithValue("@Password", Password);  
  9. SqlDataAdapter da = new SqlDataAdapter(cmd);  
  10. DataSet ds = new DataSet();  
  11. da.Fill(ds);  
  12. if (Convert.ToInt32(ds.Tables[0].Rows[0][0].ToString())>0)  
  13. {  
  14. HttpContext.Current.Session["UserID"] = Username;  
  15. return "ok";  
  16. }  
  17. else  
  18. {  
  19. // error.Visible = true;  
  20. return "UserName or Password Invalid";  
  21. }  
  22. }  
  23. }

Answers (3)