473,378 Members | 1,447 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

How to delete a Cookie in Asp.Net MVC at the click of Logout.

Hi,
I have an Asp.Net MVC application coded in C#.Net.
I have two users Admin and General User.There is a Home View which is visible to both the users.Once the user logs in there is also a Logout tab.When the user clicks the Logout or Navigates to the Home page it should get log out and the cookies should get clear.He should have to Log In again to access the Authenticated pages.
Below is how im saving the Cookies.
Expand|Select|Wrap|Line Numbers
  1. Cookie.setCookie(Value1,Value2,"Type of User"); 
  2. Creating the Cookie
  3. public static void setCookie(Value1,Value2,User)
  4. {
  5. HttpCookie MyCookie= new HttpCookie("MyCookie");
  6. MyCookie["Value1"] = Value1;
  7. MyCookie["Value2"] = Value2;
  8. MyCookie["User"] = User.ToString();
  9. MyCookie.Expires.Add(new TimeSpan(0,30,0));
  10.           HttpContext.Current.Response.Cookies.Add(MyCookie);
  11. }
  12.  
Setting
MyCookie.Expires.Add(new TimeSpan(0,30,0)); will give me 30 mins default time to expire the cookie.
But i also want to do the same when the user clicks Logout.
Please guide how can i do this.
Dec 10 '11 #1
0 2799

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: Phil Powell | last post by:
I am having this problem: My PHP script will set a cookie, it's there in my /Cookies folder. I delete the cookie (I have to for testing purposes, the PHP script I run behaves according to this...
3
by: Phil Powell | last post by:
class LoginSessionGenerator extends MethodGenerator { function LoginSessionGenerator() {} /** * Logout * * @access public */ function &logout() { // STATIC VOID METHOD
0
by: Phil Powell | last post by:
<?php class LoginSessionGenerator { /** * Logout * * @access public */ function &logout() { // STATIC VOID METHOD
0
by: Urban Bettag | last post by:
I want to use persistent cookies for my login page. For example, the user types in his username and password. He can check a box and the system should remember his username on a next visit. I have...
1
by: Henri | last post by:
Hi, My page saves user's login on user's computer using a cookie: Dim expires As Date = DateTime.Now.AddMonths(1) Dim cookie As New HttpCookie("login", loginValue) cookie.Expires = expires...
0
by: Hyphessobrycon | last post by:
hallo, why doesn't this function? Only when I select the datarow, push the delete button of the keyboard and then the btnrubriekweg button. why not immediately from the rubriekweg button only?...
5
by: ad | last post by:
Hi, How can I delete the cookie in client?
6
by: jojowebdev | last post by:
Do javascript cookies REALLY have to be this hard? function setCookie( name, value, expires, path, domain, secure ) { var today = new Date(); today.setTime( today.getTime() ); if ( expires ) {...
1
by: vj83 | last post by:
Hi, Iam working in a webapplication in which I am using RSA cookie authentication to login. I login using secure RSA ID in which i login using different users with different Tokens such as Admin ,...
3
by: TimSki | last post by:
Hi, I have the following javascript function which creates a cookie function setCookie(c_name,value,expiredays) { var exdate=new Date(); exdate.setDate(exdate.getDate()+expiredays);...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.