C#/ASP.NET: can't remove cookies with Domain property specified

asp.net tutorial
asp.net mvc
asp.net core
asp.net download
net core
asp.net application
asp.net web application
net framework

I have the following code in my login method:

Response.Cookies["cookie"].Value = "...";
Response.Cookies["cookie"].Domain = "domain.com";

This way the cookie is put into the main domain and all subdomains

However when I try to remove the cookies:

Response.Cookies["cookie"].Expires = DateTime.Now.AddYears(-1);

It doesn't work!

When I remove the 2 line of code where Domain property is specified, it works fine.

How can I solve this problem?


Okay, I figured that out.

When you remove a cookie with Domain property set, you need to set the very same property for the new fake cookie:

if (Request.Cookies["cookie"] != null)
    HttpCookie myCookie = new HttpCookie("cookie");
    myCookie.Expires = DateTime.Now.AddDays(-1d);
    myCookie.Domain = "domain.com"; // !!!!

Tutorial: Get started with C# and ASP.NET Core, NET Core using Visual Studio, you'll create a C# ASP. NET Core Web Application template, you can install it from the Create a What is C#?. You can implement your OptionalPhoneAttribute based on the original PhoneAttribute: public sealed class OptionalPhoneAttribute : ValidationAttribute { public override bool IsValid(object value) { var phone = new PhoneAttribute(); //return true when the value is null or empty //return original IsValid value only when value is not null or empty

I suspect you are setting Expires while the Response is on a subdomain... Crosscheck: Can you try and set it from the domain itself and see if that works ?

According to http://msdn.microsoft.com/en-us/library/ms178195%28v=VS.100%29.aspx you can delete a cookie by:

if (Request.Cookies["cookie"] != null)
    HttpCookie myCookie = new HttpCookie("cookie");
    myCookie.Expires = DateTime.Now.AddDays(-1d);

ASP.NET, The first concept to get is .NET which is a framework at the base of all the things you are asking about. It has libraries and functions that can be  I have a CommandArgument that takes in 1 argument from a LinkButton in my GridVie for row deletion in GridView. Code in my aspx.cs: LinkButton lnk = (LinkButton)sender; string stid = lnk.

Searched around quite a bit and couldn't get it to work. I had to actually set the value property to make it work! Using mvc 3 .net 4.

        var current = HttpContext.Current.Request.Cookies[key];
        if (current == null) return;
        var myCookie = new HttpCookie(key)
                               Expires = DateTime.Now.AddYears(-1),
                               Value = current.Value,
                               Domain = domain

Is C# .Net for desktop applications while C#/ASP .Net is for web , The framework I will be discussing in this blog post is ASP.NET and ASP.NET Core. What is ASP.NET? ASP.NET is an open source, server-side  Question: Tag: c#,asp.net-mvc I am beginner in linq and I am trying to write linq query to get data from multiple tables . IQueryable<ESSRequest> ESSRequest = from essrequest in db.ESSRequest join emps in db.HrEmpS on essrequest.HrEmp_no equals emps.HrEmp_no join emp in db.HrEmp on emps.Emp_no equals emp.Emp_no where essrequest.Next_Approval == user_id select new { essrequest, emp_name=emp.Emp

Need to set domain and value with empty string. It does not work without value.

        var cookie = new HttpCookie(cookieName, string.Empty)
            Expires = DateTime.Now.AddYears(-1),
            Domain = {YourDomain}


What is ASP.NET and Why Should I Use It? - Wakefly Blog, NET languages can talk to. .NET languages come in different flavours such as: C#.NET, VB.NET, Managed C++, F#. .NET languages compile  This feature is not available right now. Please try again later.

Relationship between C#, .NET, ASP, ASP.NET etc, NET/C#/ASP.NET will be very useful for you, you'll get good job opportunities with satisfying pay scales. 899 views ·. View 1 Upvoter. Create an ASP.NET web app by following these steps: Open Visual Studio and then select Create a new project. In Create a new project, find and choose ASP.NET Web Application (.NET Framework) for C#, then select Next. In Configure your new project, name the application myFirstAzureWebApp, and then select Create.

Is there a future in learning .NET/C#/ASP.NET?, Razor supports both C# (C sharp) and VB (Visual Basic). NET object, but objects can also be self-defined, a web page, a text box, a file, a database record, etc  The Visual Studio Code C# extension can generate the assets you need to build and debug. If you missed the prompt when you first opened a new C# project, you can still perform this operation through the Command Palette (View > Command Palette) by typing '.NET', and running .NET: Generate Assets for Build and Debug.

ASP.NET Razor C# Syntax, After completing this tutorial you will find yourself at a moderate level of expertise in ASP.NET programming from where you can take yourself to next levels. ASP.NET Web API can automatically serialize your model to JSON, XML, or some other format, and then write the serialized data into the body of the HTTP response message. As long as a client can read the serialization format, it can deserialize the object. Most clients can parse either XML or JSON.

  • Anyone? I've been struggling with this for ever....
  • Thanks for sharing your answer Alex. It helped me mate
  • Thank you for your answer. I set the cookies from the domain itself. I tried the very same example, and it works only in Opera.
  • Thanks for providing proper solution.