TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
ahmed salah
NA
530
148.3k
How to go to loggedIn view if user logged In before
Dec 4 2016 12:53 PM
I need user logged in directly when open my application if he logged in before .
meaning if i write user name sa and password 123 then open web application it will go to loggedIn view if username and password is correct
when i open my web application again go to loggedIn view directly without write user name and password(save correct usename and password correct for first time and after this no need to write user name and password)
I working with mvc .
AccountController
[HttpPost]
[ValidateAntiForgeryToken]
public
ActionResult Login(UserAccount user,
string
ReturnUrl =
""
)
{
using
(ContainerClass db =
new
ContainerClass())
{
var usr = db.userAccount.Where(u => u.UserName == user.UserName && u.Password == user.Password).FirstOrDefault();
if
(usr !=
null
)
{
FormsAuthentication.SetAuthCookie(user.UserName, user.RememberMe);
if
(Url.IsLocalUrl(ReturnUrl))
{
//return Redirect(ReturnUrl);
}
else
{
Session[
"UserID"
] = user.UserID.ToString();
Session[
"UserName"
] = user.UserName.ToString();
return
RedirectToAction(
"LoggedIn"
);
}
}
else
{
ModelState.AddModelError(
""
,
"Username or Password is wrong"
);
}
}
ModelState.Remove(
"Password"
);
return
View();
}
public
ActionResult LoggedIn()
{
if
(Session[
"UserID"
] !=
null
)
{
return
View();
}
else
{
return
RedirectToAction(
"login"
);
}
}
LoggedIn view
@{
ViewBag.Title =
"LoggedIn"
;
}
@
if
(Session[
"UserID"
]!=
null
)
{
<h4>Hellow @Session[
"UserName"
].ToString()</h4>
}
This is my model
UserAccount
public
class
UserAccount
{
[Key]
public
int
UserID {
get
;
set
; }
[Required(ErrorMessage =
"UserName is Required"
)]
public
string
UserName {
get
;
set
; }
[Required(ErrorMessage =
"Email is Required"
)]
[Required(ErrorMessage =
"Password is Required"
)]
[DataType(DataType.Password)]
public
string
Password{
get
;
set
; }
public
bool
RememberMe {
get
;
set
; }
}
}
I work with mvc code first
Reply
Answers (
2
)
How to generate Web Form in Run-time ?
ASP.NET MVC using angular js