Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6942895
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T13:05:07+00:00 2026-05-27T13:05:07+00:00

I have a asp.net MVC3 Application with two users Admin and General.Cookies is saved

  • 0

I have a asp.net MVC3 Application with two users Admin and General.Cookies is saved for both the users.
Below is how my cookies is saved.

 Cookie.setCookie(No,DOB,User); 

Have a class Cookie with the method setCookie

 public static void setCookie(int No,DateTime DOB,string User)
        {
            HttpCookie MyCookie= new HttpCookie("MyCookie");
            MyCookie["No"] = No;
            MyCookie["DOB"] = DOB;
            MyCookie["User"] = User;

            MyCookie.Expires.Add(new TimeSpan(0,30,0));

            HttpContext.Current.Response.Cookies.Add(MyCookie);
        }

Above is my Setcookie code.

MyCookie.Expires.Add(new TimeSpan(0,30,0));will give the default expiry time to 30 minutes.

What im trying is when the user click Logout the cookie should get completely cleared and the user should not be able to navigate to any of the Authenticated sections of the site.
Also i have tried this but no use

MyCookie.Expires.Add(-1);

But i have tried that in my SetCookie method.How can i make the cookies cleared when the user clicks Logout.
Also i have tried creating a Logout Method in Cookie Class like below:

  public static bool logout()
        {

            HttpCookie reqCookies = HttpContext.Current.Request.Cookies["MyCookie"];
            reqCookies.Expires.AddDays(-1);
            return true;
        }

Here im Trying to use the already saved cookie and Expire it by setting .AddDays(-1);
And im using if cookie.Logout()==true and redirecting it to my Home.
But it is giving me following error on RunTime
The added or subtracted value results in an un-representable DateTime.
Parameter name: value

Any suggestions/guidance on how can i achieve my target.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T13:05:08+00:00Added an answer on May 27, 2026 at 1:05 pm

    You can use a jquery cookie script for that.

    <a href="" onclick="removeCookie();">logout button</a>
    
    function removeCookie(){
    $.cookie('cookiename', '');
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My application is in Asp.Net MVC3, i have two Users(Admin and general).Im maintaining the
In my ASP.NET MVC 3 application i have two types of users - regular
My application is in Asp.Net MVC3 coded in C#.Net. I have Views which contains
I have an ASP.NET MVC3 application in which I am creating multiple areas, is
Here's the issue at hand: I have developed an ASP.NET MVC3 application using Razor.
I am building an asp.net mvc3 application and I have decided to use areas
I have the following WebGrid in my ASP.NET MVC3 test application. It displays a
I have an ASP.NET MVC3 application in C# and Razor. In the view MyView
Well, this is an interesting problem. I have an ASP.NET MVC3 Intranet application running
I have a Razor view in my asp.net MVC3 application with a dropdownlist like

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.