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#
- ASP.NET MVC Cookie loses value when page is changed
- Global Variable loses its value after page index changed in DataGrid
- .NET MVC client side validation not showing message for property when value invalid
- Why JQuery is unable to get Textarea value when the visible changed to false?
- MVC 3 - Getting on server side the value from a dropdown changed on javascript
- MVC 4 - hand over changed value from View to Controller
- ASP.NET MVC Controller causing page reload when uploading a Blob
- MVC cannot get the value from code to html page
- How to make asp.net mvc convert an array of strings to an array of value types when model binding?
- What Event Handler is called when C# ComboBox value is changed by Typing
- Return to a certain div when a page reloaded. (ASP.NET MVC 5)
- How to get the textbox changed value for Update in @Html.ActionLink in MVC
- ASP.NET ListView-embedded Web-Control loses state and passed-values on ItemDataBound event handler when page posts back
- Remember Cascading Dropdown value when navigating away from page
- Do not trigger cell value change event in DataGridView when the value is changed programatically
- Refresh/Reload MUI WPF Page when Tab is Changed
- Showing last cookie value on Relogin (i.e. Again login after logout) in Asp.net MVC with Razor
- Does MVC page load faster when you pass a empty model to View?
- MVC All DropdownListsFor are returning Error : "The value Cannot be Null, Parameter name:Items" After POST, Works Perfectly populating when GET
- Date value is getting changed when saving to database
- Datagridview cell loses input value when focus is lost
- Null Reference Exception in MVC 4 View Page when used in data-originalvalue attribute?
- IIS is Redirecting to a 404 Error Page When There is a Hash Value (#) in the URL That Includes a Period
- MVC C# - The value 'checked' is not valid when I use a checkbox
- ASP.NET MVC 5 Razor throws 'Nullable object must have a value' even when the object has value
- ASP.NET MVC 5 Wrong Redirect Login Page
- VS2013 ASP.NET MVC Single Page Application Template Auto Redirection
- MVC 4 Razor _Layout.cshtml use a HTML section for only one page
- asp.net mvc login form in layout page (The partial view 'LogIn' was not found)
- Error for Null value when opening a registry key in C#
- Determine if PipeStream has data
- Unit testing an existing ASP.NET MVC controller
- In C# assigning result of addition of two byte variables to another byte variable generates error, can be assigned only to int variable
- C# owin web api route index page
- How to fetch the id from Caraousel and display the information about specific image?
- After merged files image color changed from white on red
- Unit Test Adapter threw exception: ... is not marked as serializable
- How can I use WPF MediaKit, or a similar program, for rendering from a DirectShow filter graph created with DES on to a WPF control?
- My website is displaying Arabic text as question mark symbols
- How to determine whether a C# control is being unloaded?
- How to handle multiple object types when creating a new Type
- Isn't C# finalizer mechanics fundamentally flawed even for the case it was designed for?
- Asp.Net SQL Delete Statement
- What does operator + in method definition do?
- Visual Studio Code Snippet Refactoring
- How do I map AWS API Gateway query string to C# AWS Lambda function?
- Fetch RTF from Word
- Unable to add Microsoft Office Interop Assembly to Project
- Visual studio 2012 project property "Always Start when Debugging"
- Dependency Injection for my custom UserManager WITHOUT Identity