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#
- Silverlight Combobox loses visual value, but keeps selected value when the page it's on is hidden and reshown
- MVC web application in the global.asax, when session time out how to get the cookie value
- ASP.NET MVC showing error page on when sending responses with status 500
- Redirect to MVC ActionResult with Parameters when DropDownList option is changed
- Rx IObservable produce value only when value has changed by a certain margin
- MVC 3 unobtrusive javascript validation when textbox has a default value
- WPF Slider - notify when value was changed from UI
- Navigate to another page when orientation changed
- Page still shows after logout when back button is clicked asp.net mvc 3
- Why is the ValueChanged event not triggered on a NumericUpDown Control When the Value is Changed Manually?
- auto press enter C# when textbox value changed as event
- String truncated when assigning to input text value in asp .net mvc
- How to count checked checkboxes in DataGridView when Checkbox value is changed in c#?
- ASP. Net Core 2.2 with cookie authentication: how to avoid page redirect when not authorized for API only controllers
- When can I guarantee value changed on one thread is visible to other threads?
- Load data only when page is scrolled down MVC 4 Jquery Mobile
- Get which Registry value changed when RegNotifyChangeKeyValue triggered in c#
- How to keep the selected value from the dropdown when the page is changed?
- Is it possible to Display validation errors when page loads in MVC - 4 (with model validations)
- MVC 4, How to populate 3 textboxs when Autocomplete value is selected?
- alert shows undefined in javascript when passed value form aspx.cs page
- Passing Value when Select on GridView to another page
- Propertychanged event firing even when property value not changed
- Browser back button does not populate dropdowns value in MVC application
- When Using '/' character in history.pushState, MVC rewrite the URL
- Determine which ASP.NET MVC View to return when not using return View(model) but return View("viewName", model)
- How to "Forward" a cookie to another page
- NullReferenceException when set value to a property
- C# creating a custom NumberFormatInfo to display "Free" when a currency value is $0.00
- Visual Studio loses reference when attempting to build
- Convert Char[] to a List<byte> (c#)
- Super slow C# custom control
- C# prevent SQL injection for create statement
- Generating User-Friendly URLs
- Why are some TemplateBinding values not shown in designer but others are? [with repro code]
- Digitally sign in PHP using private key, verify in C#
- Why is the minimum size of a reference type 12 bytes for a 32 bit .NET process
- Deserializing dynamic JSON
- ASP.NET MVC 5: Define route order across controllers (RouteAttribute)
- Is having circular soft dependencies between projects considered a good design?
- C# Console Application User-Editable Settings
- Pausing a new BackGroundWorker until previous completes
- How to save date student's absence in SQL Server?
- MVC Ajax Form returning entire contents of View
- How can I get a string[] of all different values of a list?
- MediaElement in Canvas doesnt Strech to Fill
- Finding Label in GridTableView (RadGrid)
- .NET/C# check if SQL query modifies database and if not execute
- Providing an Implementation of an Interface for Moq to Use
- Behavior in WinForm/Console Hybrid Application