I’m working on Web application in which I have to implement remember me feature for that I decided to create a cookie for storing the username of the user.
Issue – When a user logs in to my Web Application, I create a cookie for storing the username of the user.But when the user redirects the page from logging in to another page, the cookie loses its value. I’m not getting the cookie value in another action method. Strange thing is that the cookie is still there but its value is empty.
I’ve double-checked my code and debug also to ensure that the cookie doesn’t get rewritten. After struggling for 1-2 hours in Google I find out the solution to the issue. So that I decided to write the solution that worked for me.
Point in the Post:
- ASP.NET MVC Cookie gets deleted after redirect to action
- Response.Cookies gets reset when RedirectToAction is called
- Implement Remember Me with Login in ASP.Net MVC
We just need to set the cookie. Secure property to false.
HttpCookie _rememberme = new HttpCookie("_rememberme"); _rememberme.Expires = DateTime.Now.AddDays(30); _rememberme["UserName"] = ac.UserName; _rememberme["Password"] = ac.Password; _rememberme.Secure = false; //this line of code is responsible for that Response.Cookies.Add(_rememberme);
There are many types of files in our mobiles and laptops, out of which cookies are also a normal text file present in our hard drive which is automatically saved from the Internet.
Whenever we open a website, all its information is saved in a file so that whenever we open a website again, it is easier to open any page related to it, and thus we also take less time. And the data cost is also less.
If we talk technically, it works like a kind of identification card which is very important for advertising size and e-commerce websites on the internet because it is very effective to show all types of ads related to them.
Just as the names of their operating systems are placed on food items in Android mobiles, similarly the name of Internet Cookies is associated with a food item. So today we will tell you in this article what is cookies and how does it work and what are its benefits.
The post [Solved]-Cookie loses value when page is changed in MVC appeared first on Software Development | Programming Tutorials.
Read More Articles
- Write a value which contain comma to a CSV file in c#?
- Reading CSV File with cells containing commas c#
- Split CSV with columns may contain ‘,’ Comma C#
- [Simple Way]-Cascading DropDownList in Asp.Net Mvc Using Jquery Ajax
- [Simple Way]-How to get data from database using JQuery Ajax in asp net MVC
- [Simple Way]-ASP.NET Core Upload Multiple File Web API model
- [Simple Way]- Image Upload in .NET Core Web API
- [Easy Way]-Receive File and other form data together in ASP.NET Core Web API
- Replace image in word document using C#
- How to add new rows to an existing word document table in C#
- Simple Way Find and replace text in Word document using C#
- Implementing “Remember Me” Feature in ASP.NET MVC
- [Solved]-Cookie loses value when page is changed in MVC
- How to post File Upload and other form fields to one action Asp .Net MVC C#
- How To Post File and Data to API using HttpClient C#
- Create ASP.NET Core Web API Without Entity Framework
- .NET Core Web API Using Code First Entity Framework Approach
- Create Asp.Net Core Web Api Using Entity Framework Database First
- Registration form with image upload in MVC using jquery Ajax
- How to make an Inline editable table in MVC using jquery?
- CRUD operation using partial view in MVC with modal popup
- Insert Update Delete Using Jquery Ajax and Modal Popup in Mvc
- Crud Operations in MVC Without Entity Framework
- Create Login,Signout and Registration in Asp .Net Mvc Using Entity
- Export Gridview to Excel and Csv in Asp .Net With Formatting Using c#
- How to Display Binary Image in Gridview from Database in Asp .Net c#
- [Solved]-How to Upload pdf file using jquery MVC?
- [Solved]-Uploading both data and files in FormData using Ajax MVC
- C# -Saving a base64 string as an image into a folder on server in Web Api
- [Solved]-Download pdf file from link and save in local file folder in Asp .Net
- [Solved]-Delete Files older than X Months,Days,Minute in a Directory- C# .NET
- [Solved]-LEFT OUTER JOIN in LINQ With Where clause in C#
- INNER JOIN,RIGHT JOIN,LEFT JOIN USING LINQ IN Multiple Table C#
- [Solved]-Convert Base64 To Image And Save in folder and Display it- C#
- [Solved]-How to Overlay Two Images in .NET-C#
- How to Create Multilingual Website in Asp .Net
- C# – How to add double quotes to a string that is inside a variable
- Update an Image with Upload Button For Each Row in Gridview-Asp .Net
- How to Bind Data in DataList Control in Asp.Net – C#
- Upload and Display an Image in Gridview From Image Path in Database -C#