How to use Session thru Login, Authorization,Authentication?
up vote
0
down vote
favorite
First of all i am a newbie when it comes to programming and i am only self-learning and would like to ask for solutions that i have encountered and can't be solved by my own
I Can't make it work. i would like Session["userlevel"] == "Admin" to be the only one to access the view how can i make this to work please help..
public ActionResult Authorize(Test user)
{
using (TableEntities db = new TableEntities())
{
var loginUserAdmin = db.Employees.Where(x => x.Username == user.Username && x.UserPassword == user.UserPassword && x.AccountStatus == "Active" && x.AccountType == "Admin").FirstOrDefault();
if (loginUserAdmin == null || loginUserAdmin != loginUserAdmin)
else
ViewBag.Messageko = "Admin";
Session["userid"] = loginUserAdmin.EmployeeID;
Session["firstName"] = loginUserAdmin.FirstName;
Session["lastName"] = loginUserAdmin.LastName;
Session["userName"] = loginUserAdmin.Username;
Session["userPassword"] = loginUserAdmin.UserPassword;
Session["userlevel"] = loginUserAdmin.AccountType;
ViewBag.acc = loginUserAdmin.AccountType;
return RedirectToAction("Dashboard", "Test" ,"Login");
this is my Dashboard Controller
[HttpGet]
public ActionResult Dashboard()
TableEntities db = new TableEntities();
ViewBag.Active = db.Employees.Where(x => x.AccountStatus == "Active");
ViewBag.Message = "GG";
return View();
And this is my View
@
ViewBag.Title = "Dashboard";
Layout = "~/Views/Shared/_Layout.cshtml";
@if (Session["userlevel"].ToString() == "Admin")
Response.Redirect("~/Test/Login");
else
if (ViewBag.Active != null)
<label style="font-size:12px; color:red;">@ViewBag.Messageko</label>
<table class="table table-striped">
<tr>
<th>EmployeeID</th>
<th>First Name</th>
<th>Middle Name</th>
<th>Last Name</th>
<th>User Name</th>
<th>User Password</th>
<th>Account Status </th>
</tr>
@foreach (var User in ViewBag.Active)
<tr>
<td align="center">@User.EmployeeID</td>
<td align="center">@User.FirstName</td>
<td align="center">@User.MiddleName</td>
<td align="center">@User.LastName</td>
<td align="center">@User.Username</td>
<td align="center">@User.UserPassword</td>
<td align="center" class="text-success">@User.AccountStatus</td>
</tr>
</table>
Thank you Very Much
asp.net-mvc-5
add a comment |
up vote
0
down vote
favorite
First of all i am a newbie when it comes to programming and i am only self-learning and would like to ask for solutions that i have encountered and can't be solved by my own
I Can't make it work. i would like Session["userlevel"] == "Admin" to be the only one to access the view how can i make this to work please help..
public ActionResult Authorize(Test user)
{
using (TableEntities db = new TableEntities())
{
var loginUserAdmin = db.Employees.Where(x => x.Username == user.Username && x.UserPassword == user.UserPassword && x.AccountStatus == "Active" && x.AccountType == "Admin").FirstOrDefault();
if (loginUserAdmin == null || loginUserAdmin != loginUserAdmin)
else
ViewBag.Messageko = "Admin";
Session["userid"] = loginUserAdmin.EmployeeID;
Session["firstName"] = loginUserAdmin.FirstName;
Session["lastName"] = loginUserAdmin.LastName;
Session["userName"] = loginUserAdmin.Username;
Session["userPassword"] = loginUserAdmin.UserPassword;
Session["userlevel"] = loginUserAdmin.AccountType;
ViewBag.acc = loginUserAdmin.AccountType;
return RedirectToAction("Dashboard", "Test" ,"Login");
this is my Dashboard Controller
[HttpGet]
public ActionResult Dashboard()
TableEntities db = new TableEntities();
ViewBag.Active = db.Employees.Where(x => x.AccountStatus == "Active");
ViewBag.Message = "GG";
return View();
And this is my View
@
ViewBag.Title = "Dashboard";
Layout = "~/Views/Shared/_Layout.cshtml";
@if (Session["userlevel"].ToString() == "Admin")
Response.Redirect("~/Test/Login");
else
if (ViewBag.Active != null)
<label style="font-size:12px; color:red;">@ViewBag.Messageko</label>
<table class="table table-striped">
<tr>
<th>EmployeeID</th>
<th>First Name</th>
<th>Middle Name</th>
<th>Last Name</th>
<th>User Name</th>
<th>User Password</th>
<th>Account Status </th>
</tr>
@foreach (var User in ViewBag.Active)
<tr>
<td align="center">@User.EmployeeID</td>
<td align="center">@User.FirstName</td>
<td align="center">@User.MiddleName</td>
<td align="center">@User.LastName</td>
<td align="center">@User.Username</td>
<td align="center">@User.UserPassword</td>
<td align="center" class="text-success">@User.AccountStatus</td>
</tr>
</table>
Thank you Very Much
asp.net-mvc-5
Please could somebody help me through this problem..
– Clarence Baluyot
Nov 15 at 6:57
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
First of all i am a newbie when it comes to programming and i am only self-learning and would like to ask for solutions that i have encountered and can't be solved by my own
I Can't make it work. i would like Session["userlevel"] == "Admin" to be the only one to access the view how can i make this to work please help..
public ActionResult Authorize(Test user)
{
using (TableEntities db = new TableEntities())
{
var loginUserAdmin = db.Employees.Where(x => x.Username == user.Username && x.UserPassword == user.UserPassword && x.AccountStatus == "Active" && x.AccountType == "Admin").FirstOrDefault();
if (loginUserAdmin == null || loginUserAdmin != loginUserAdmin)
else
ViewBag.Messageko = "Admin";
Session["userid"] = loginUserAdmin.EmployeeID;
Session["firstName"] = loginUserAdmin.FirstName;
Session["lastName"] = loginUserAdmin.LastName;
Session["userName"] = loginUserAdmin.Username;
Session["userPassword"] = loginUserAdmin.UserPassword;
Session["userlevel"] = loginUserAdmin.AccountType;
ViewBag.acc = loginUserAdmin.AccountType;
return RedirectToAction("Dashboard", "Test" ,"Login");
this is my Dashboard Controller
[HttpGet]
public ActionResult Dashboard()
TableEntities db = new TableEntities();
ViewBag.Active = db.Employees.Where(x => x.AccountStatus == "Active");
ViewBag.Message = "GG";
return View();
And this is my View
@
ViewBag.Title = "Dashboard";
Layout = "~/Views/Shared/_Layout.cshtml";
@if (Session["userlevel"].ToString() == "Admin")
Response.Redirect("~/Test/Login");
else
if (ViewBag.Active != null)
<label style="font-size:12px; color:red;">@ViewBag.Messageko</label>
<table class="table table-striped">
<tr>
<th>EmployeeID</th>
<th>First Name</th>
<th>Middle Name</th>
<th>Last Name</th>
<th>User Name</th>
<th>User Password</th>
<th>Account Status </th>
</tr>
@foreach (var User in ViewBag.Active)
<tr>
<td align="center">@User.EmployeeID</td>
<td align="center">@User.FirstName</td>
<td align="center">@User.MiddleName</td>
<td align="center">@User.LastName</td>
<td align="center">@User.Username</td>
<td align="center">@User.UserPassword</td>
<td align="center" class="text-success">@User.AccountStatus</td>
</tr>
</table>
Thank you Very Much
asp.net-mvc-5
First of all i am a newbie when it comes to programming and i am only self-learning and would like to ask for solutions that i have encountered and can't be solved by my own
I Can't make it work. i would like Session["userlevel"] == "Admin" to be the only one to access the view how can i make this to work please help..
public ActionResult Authorize(Test user)
{
using (TableEntities db = new TableEntities())
{
var loginUserAdmin = db.Employees.Where(x => x.Username == user.Username && x.UserPassword == user.UserPassword && x.AccountStatus == "Active" && x.AccountType == "Admin").FirstOrDefault();
if (loginUserAdmin == null || loginUserAdmin != loginUserAdmin)
else
ViewBag.Messageko = "Admin";
Session["userid"] = loginUserAdmin.EmployeeID;
Session["firstName"] = loginUserAdmin.FirstName;
Session["lastName"] = loginUserAdmin.LastName;
Session["userName"] = loginUserAdmin.Username;
Session["userPassword"] = loginUserAdmin.UserPassword;
Session["userlevel"] = loginUserAdmin.AccountType;
ViewBag.acc = loginUserAdmin.AccountType;
return RedirectToAction("Dashboard", "Test" ,"Login");
this is my Dashboard Controller
[HttpGet]
public ActionResult Dashboard()
TableEntities db = new TableEntities();
ViewBag.Active = db.Employees.Where(x => x.AccountStatus == "Active");
ViewBag.Message = "GG";
return View();
And this is my View
@
ViewBag.Title = "Dashboard";
Layout = "~/Views/Shared/_Layout.cshtml";
@if (Session["userlevel"].ToString() == "Admin")
Response.Redirect("~/Test/Login");
else
if (ViewBag.Active != null)
<label style="font-size:12px; color:red;">@ViewBag.Messageko</label>
<table class="table table-striped">
<tr>
<th>EmployeeID</th>
<th>First Name</th>
<th>Middle Name</th>
<th>Last Name</th>
<th>User Name</th>
<th>User Password</th>
<th>Account Status </th>
</tr>
@foreach (var User in ViewBag.Active)
<tr>
<td align="center">@User.EmployeeID</td>
<td align="center">@User.FirstName</td>
<td align="center">@User.MiddleName</td>
<td align="center">@User.LastName</td>
<td align="center">@User.Username</td>
<td align="center">@User.UserPassword</td>
<td align="center" class="text-success">@User.AccountStatus</td>
</tr>
</table>
Thank you Very Much
asp.net-mvc-5
asp.net-mvc-5
asked Nov 11 at 13:12
Clarence Baluyot
11
11
Please could somebody help me through this problem..
– Clarence Baluyot
Nov 15 at 6:57
add a comment |
Please could somebody help me through this problem..
– Clarence Baluyot
Nov 15 at 6:57
Please could somebody help me through this problem..
– Clarence Baluyot
Nov 15 at 6:57
Please could somebody help me through this problem..
– Clarence Baluyot
Nov 15 at 6:57
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
In Visual Studio 2015 @if (Session["userlevel"].ToString() == "Admin") works!!
But in 2017 i dont know but
@if (Session["userlevel"].ToString().Trim() == "Admin") works!!
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
In Visual Studio 2015 @if (Session["userlevel"].ToString() == "Admin") works!!
But in 2017 i dont know but
@if (Session["userlevel"].ToString().Trim() == "Admin") works!!
add a comment |
up vote
0
down vote
In Visual Studio 2015 @if (Session["userlevel"].ToString() == "Admin") works!!
But in 2017 i dont know but
@if (Session["userlevel"].ToString().Trim() == "Admin") works!!
add a comment |
up vote
0
down vote
up vote
0
down vote
In Visual Studio 2015 @if (Session["userlevel"].ToString() == "Admin") works!!
But in 2017 i dont know but
@if (Session["userlevel"].ToString().Trim() == "Admin") works!!
In Visual Studio 2015 @if (Session["userlevel"].ToString() == "Admin") works!!
But in 2017 i dont know but
@if (Session["userlevel"].ToString().Trim() == "Admin") works!!
answered Nov 26 at 5:02
Clarence Baluyot
11
11
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53249074%2fhow-to-use-session-thru-login-authorization-authentication%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Please could somebody help me through this problem..
– Clarence Baluyot
Nov 15 at 6:57