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
Guest User
Tech Writer
611
129.4k
remember me in mvc with jquery.
Mar 27 2020 7:13 AM
public ActionResult Login(string EmailId, string Password, bool RememberMe)
{
FanzdbEntities _db = new FanzdbEntities();
AdminMaster Obj_AdminMaster = new AdminMaster();
HttpCookie cookie = new HttpCookie("UserDetail");
try
{
//if (ModelState.IsValid == true)
//{
if (RememberMe == true)
{
cookie["FirstName"] = EmailId;
byte[] b = ASCIIEncoding.ASCII.GetBytes(Password);
String EncryptedPassword = Convert.ToBase64String(b);
cookie["Password"] = EncryptedPassword;
cookie.Expires = DateTime.Now.AddDays(1);
HttpContext.Response.Cookies.Add(cookie);
}
else
{
cookie.Expires = DateTime.Now.AddDays(-1);
HttpContext.Response.Cookies.Add(cookie);
}
$('#btnAdminLogin').click(function () {
if ($('#txtEmailId').val() == "" || $('#txtPassword').val() == "" || $('#lblRemeber').val()) {
alert("Please fill all required fields");
return false;
}
var RememberMe = $('#exampleCheck1').prop('checked');
if (RememberMe == true) {
$.ajax({
url: 'Login/Login',
type: 'Post',
dataType: 'json',
data: {
"EmailId": $('#txtEmailId').val(), "Password": $('#txtPassword').val(), "RememberMe": RememberMe
},
success: function (data) {
var status = data.status;
if (status == true) {
var url = "/UserManagement/AllUsers";
window.location.href = url;
}
else {
alert("wrong credentials");
return false;
}
},
failure: function (data) {
alert("Something went wrong");
}
});
}
else {
$.ajax({
url: 'Login/Login',
type: 'Post',
dataType: 'json',
data: { "EmailId": $('#txtEmailId').val(), "Password": $('#txtPassword').val(), "RememberMe": RememberMe },
success: function (data) {
var status = data.status;
if (status == true) {
var url = "/UserManagement/AllUsers";
window.location.href = url;
}
else {
alert("wrong credentials");
return false;
}
},
failure: function (data) {
alert("Something went wrong");
}
});
}
});
</script>
It's me remeber me code .with jqury it's working fine. I have set cookies value this code.
But i have face a problem I have reload a page and logout button click fill text box with EmailId and Password .
I want to fill this text box . how to this task possible with mvc and jquery.
Reply
Answers (
1
)
How to Publish C# App along with remotely central database?
What are all the things need to know in .net?