Hi skp,
Opening a page in a new tab or window will cause a new session to be initiated. So using sessionStorage for this is not possible.
For this you should use localStorage.
Check this example. Now please take its reference and correct your code.
Model
public class user
{
public string username { get; set; }
public string password { get; set; }
}
Controller
public class HomeController : Controller
{
// GET: /Home/
public ActionResult Index()
{
return View();
}
public JsonResult userlogin(user us)
{
string result = "1";
return Json(result, JsonRequestBehavior.AllowGet);
}
}
View
Index
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Index</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" />
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script type="text/javascript" src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.6.8/angular.min.js"></script>
<script type="text/javascript" src="https://cdn.jsdelivr.net/ngstorage/0.3.6/ngStorage.min.js"></script>
<script type="text/javascript">
var app = angular.module('MyApp', ["ngStorage"])
app.controller('MyController', function ($scope, $localStorage, $http, $window) {
$scope.user = {
"username": "sa",
"password": "123"
};
$scope.login = function () {
$localStorage.LocalMessage = $scope.user;
$http({
method: "POST",
url: '/Home/userlogin',
params: $scope.user,
dataType: "json",
headers: { "Content-Type": "application/json" }
}).then(function (response) {
if (response.data == 1) {
$window.open('http://localhost:6181/Warehouse/dashboard.html');
}
else {
$localStorage.LocalMessage = "";
alert(response.data);
}
$scope.user = null;
});
}
});
</script>
</head>
<body ng-app="MyApp" ng-controller="MyController">
<section class="container ">
<div class="main_cont register">
<div class="login-panel">
<h3 class="login-heading"></h3>
<div class="row">
<div class="col-md-12 col-sm-12">
<div class="form-group">
<input type="text" class="form-control" placeholder="Username" ng-model="user.username" name="username" />
</div>
<div class="form-group">
<input type="password" class="form-control" placeholder="Password" ng-model="user.password" name="password" />
</div>
<div class="float-right">
<input type="submit" class="btn btn-primary" value="Login" ng-click="login()" />
</div>
</div>
</div>
</div>
</div>
</section>
</body>
</html>
dashboard.html
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
</head>
<body>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.6.8/angular.min.js"></script>
<script type="text/javascript" src="https://cdn.jsdelivr.net/ngstorage/0.3.6/ngStorage.min.js"></script>
<script type="text/javascript">
var app = angular.module('MyApp', ["ngStorage"])
app.controller("MyController", function ($scope, $localStorage, $window) {
var user = $localStorage.LocalMessage;
$window.alert("User Name : " + user.username + "\nPassword : " + user.password);
});
</script>
<div ng-app="MyApp" ng-controller="MyController">
</div>
</body>
</html>
Screenshot