Thursday, October 27, 2011

Deleting Session Data,Cookies and Internet Cache

 (Author: Shanthi Karthika)
Session Management is the major piece of application development. Maintaining a session will enable the user to login without giving their credentials for the second time. If we want to avoid the user re-login with same credentials we have to clear the session where the user credentials are present which enable the user to login again and again.
Recently I was in need to access each social medias (gmail,twitter and facebook) login page to get the user credentials. Here each social medias will maintain a session each time I make a request to access the page. Because of this, I faced a problem once a user provides their credential to the twitter or facebook a session was maintained, so that when I passed the request for the second time the credentials of the same user who have logged before were passed. Because of this the next users credentials or the different credentials of the same user were not able to pass. I struck upon with this half past a day. I tried deleting the cookies and Internet cache of my browser that i used, but nothing gave me a hand. Then I came to know each media maintains a session so that it can get the credentials of the user first logged in.
To delete the session data following code can be followed.
 
private const int INTERNET_OPTION_END_BROWSER_SESSION = 42;

DLL for deleting session data:

[DllImport("wininet.dll", SetLastError = true)]
private static extern bool InternetSetOption(IntPtr hInternet, int dwOption, IntPtr lpBuffer, int lpdwBufferLength);

Use this method wherever need to clear session.

InternetSetOption(IntPtr.Zero, INTERNET_OPTION_END_BROWSER_SESSION, IntPtr.Zero, 0);

I used this method to clear the session datas and that worked fine. Now i am able to pass the request and get the different credentials.
On trying to delete the Internet cache and the cookies.I found many samples stating the same process of getting all the files in which cookie were present. But I found a difficulty in deleting index.dat file. I searched for half past day for deleting the cookies and cache. Finally I got up with the following solution
System.Diagnostics.Process.Start("rundll32.exe", "InetCpl.cpl,ClearMyTracksByProcess 8"); // Clear Temporary Files
 
System.Diagnostics.Process.Start("rundll32.exe", "InetCpl.cpl,ClearMyTracksByProcess 2"); // Clear Cookies

with this it attempts to open a seperate window which is not needed for a user. To rectify this new window opening,following can be done which runs as a background process.
try
{
System.Diagnostics.ProcessStartInfo processInfo = new System.Diagnostics.ProcessStartInfo("rundll32.exe", "InetCpl.cpl,ClearMyTracksByProcess 8");
 
processInfo.CreateNoWindow = true;
processInfo.WindowStyle = ProcessWindowStyle.Hidden;
processInfo.UseShellExecute = true;
processInfo.RedirectStandardOutput = false;
Process.Start(processInfo);

System.Diagnostics.ProcessStartInfo newprocessInfo = new System.Diagnostics.ProcessStartInfo("rundll32.exe", "InetCpl.cpl,ClearMyTracksByProcess 2");
 
newprocessInfo.CreateNoWindow = true;
newprocessInfo.WindowStyle = ProcessWindowStyle.Hidden;
newprocessInfo.UseShellExecute = true;
newprocessInfo.RedirectStandardOutput = false;
Process.Start(newprocessInfo);
}
catch(Exception error)
{
throw error;
}
you cannot see any window but the cache and cookies will be deleted.
The above code will delete all the cookies and Temporary files but the code below can be used for deleting particular cookies. Here I have given about deleting only gmail cookies.
 
String[]gmailCookies=System.IO.Directory.GetFiles(Environment.GetFolderPath(Environment.SpecialFolder.Cookies));
foreach (string currentFile in gmailCookies)
{
if (!(currentFile.EndsWith(“index.dat”)))
{
using (StreamReader streamreader = File.OpenText(currentFile))
{
string readContent = streamreader.ReadToEnd();
if (readContent.Contains(“google.com”) ||readContent.Contains(“google.co.in”))
{
streamreader.Dispose();
streamreader.Close();
System.IO.File.Delete(currentFile);
}
}
}
}

26 comments:

Ethan Wade said...

Great post, what you said is really helpful to me. I agree with you anymore. I have been talking with my friend about, he though it is really interesting as well. Keep up with your good work, I would come back to you.

Oliver Maurice said...

You should take a look here for some info on how to write great essay about world leaders in the educational system ratings. Make sure to do it as soon as possible

Aaron Yan said...

Marvelous Designer Enterprise Crack Free Download is a powerful three-dimensional dynamic software used to create virtual fashion for clothing design and 3D character clothing for video games, movies, and cartoons.marvelousdesignerenterprise

Unknown said...

iZotope VocalSynth 2 Crack Download: Color and shape of vocals with 5 combined creative must-haves and studio effects in stompbox-style. An attitude to the sounds of the past, present, and future.izotopevocalsynthserialkey

Unknown said...

Nembrini Audio – NA Blackice Beta Gamma Crack Download: The latest bass sounds have a dynamic and complex sound that can be obtained using a variety of recording tools and techniques.nembriniaudionablackicebetagamma

Alison john said...

NI LabVIEW Crack Key Free is an advanced integrated development environment (IDE) that provides line-of-text graphical programming methods for building applications.nilabviewregistrationkey

Alison john said...

reWASD 5.6.0.3306 Crack is a gamepad planning apparatus that permits you to remap your Xbox One, Elite, and 360 regulators to your console and mouse. rewasdlicensecode

David Lion said...

The greatest platform for reviewing development projects in a variety of industries is LabVIEW software. This software is what I use for text-based editing with a language-specific style device.
It's an open-air laboratory where items and chemicals are tested.
NI LabVIEW

serialsbank said...

He?lo to every one, it’s really a fastid?ou? for me to go to ?ee th?s website, it include? important Information.
Push Video Wallpaper Crack

serialsbank said...

He?lo to every one, it’s really a fastid?ou? for me to go to ?ee th?s website, it include? important Information.
D16 Group SilverLine Collection Crack

Alex Trebek said...

Air France is the worlds top domestic and international aircraft. If you plan to cancel your Air France flight, we suggest that you also study more about Air France cancellation policy and easy returns. Travellers can book a ticket through airlines have up to 24 hours before their flight to cancel. Additionally, if a flight is cancelled within 24 hours of purchase, there is no cancellation cost. If you want to cancel 24 hours in advance, you must reserve your ticket at least seven days ahead of time. If a flight is cancelled many hours before departure, the passenger is responsible for the cancellation fee. Cancellation fees may also vary depending on the fare type.

Ben anderson said...

Hey ben this side,
Your information is quite informative and has greatly aided me. You said exactly what a traveller or any person needs to know because when they travel for the first time abroad, they need to know about the location, surroundings, where they would stay, and many other things. You emphasise these types of things in your post, making it that much more useful to travellers. I also learned a lot from your article.We're on the road again after this pandemic.
thanks to lufthansa airlines manage booking
Thanks a lot for your kind information.

News Blog Posts said...

9xflix is an excellent location to watch movies if you're seeking for a new spot to view them. It allows you to watch high-definition live videos, movies, and web series, and it has a big selection of titles in a variety of categories. The best part about this service is that registration is entirely free.


Buy Crypto Currency said...

The main distinction between the platforms is that the quality Coinbase could be a broker. In different words, it helps you get access to Bitcoin and it charges you an enormous fee for it. If you've got a high enough mercantilism volume, you'll avoid a number of the upper rate fees concerned for lower purchases.


Read More:- coinbase issues

Flysair said...


The main distinction between the platforms is that the quality

The main distinction between the platforms is that the quality

Flysair said...

Nice blog Explore Sun Country Airlines

Oscar said...

The airline's upgrade possibilities are a crucial factor in setting itself apart from the competition, enabling passengers to enjoy a luxurious journey even beyond regular classes. This thorough investigation explores the complexities behind Qatar airways upgrade cost providing insight into the variables that affect pricing, the value proposition for travellers, and the manner in which these expenses relate to the larger aviation sector.

Tradeflock said...

Discover a wide array of companies owned by Tata, a renowned multinational conglomerate. Gain insights into their diverse business ventures, from automobiles and steel production to hospitality and telecommunications. Explore the extensive reach and innovation of Tata's companies, driving global growth and making a significant impact in various industries.

Ready For Travels said...

ReadyForTravels is your go-to source for comprehensive information on Qatar Airways Karachi Office in Pakistan. Whether you're a frequent flyer or planning your first journey, our user-friendly platform offers insights into the location, contact details, and services provided by Qatar Airways in Karachi. Stay updated on office hours, address, and essential contact information, ensuring a seamless travel experience. ReadyForTravels is committed to empowering travelers with accurate and up-to-date details, ensuring you're well-informed for a stress-free travel encounter with Qatar Airways in Karachi, Pakistan.

samanthajenao said...

AirlinesOffices serves as a comprehensive resource for travelers seeking detailed information about Southwest Terminal STL – St. Louis International Airport. Navigating through the intricacies of this terminal is made effortlessly accessible through our website. We offer insights into Southwest Airlines' operations at STL, including check-in procedures, amenities, and services available to passengers. From arrival to departure, AirlinesOffices provides a valuable guide, ensuring a seamless travel experience for those utilizing Southwest Terminal at St. Louis International Airport. Stay informed and travel confidently with the assistance of AirlinesOffices' comprehensive coverage. https://airlinesoffices.com/blog/southwest-terminal-stl-st-louis-international-airport/

Oliviajen said...

CorporatesOffice serves as a comprehensive resource, offering detailed insights into the Vivint Corporate Office Headquarters. By navigating through our website users can access crucial information about Vivint's corporate presence. We meticulously presents details such as address, contact information, and key executives, providing a valuable reference for individuals seeking to engage with or understand the operations of Vivint's corporate office. Whether for business inquiries or general knowledge, CorporatesOffice serves as a go-to source, consolidating pertinent data and facilitating a seamless exploration of Vivint's corporate landscape.

Captain Infotech said...

It is very useful.
Get the MBA Project Report at an affordable price from Solve Zone. Book your MBA project sample on unique topics with an approval guarantee.
Url :- https://www.solvezone.in/mba-project-report-making-service

Christian Sanford said...

Helping blog ,thank you for sharing
Christian Sanford

Oscar said...

Malaysia airlines cancellation policy is designed to provide passengers with flexibility and clarity when it comes to modifying or canceling their bookings. By understanding the fare types cancellation fees, refund eligibility criteria, and procedures, passengers can make informed decisions and navigate the cancellation process smoothly. In case of special circumstances or emergencies Malaysia Airlines may offer exceptions or waivers to its standard policy, underscoring its commitment to passenger satisfaction and service excellence.

Liarose said...

Bananas are well-known for their nutritional value and convenience as a snack, but did you know about banana stem juice benefits for health. Often overlooked, banana stem juice is a treasure trove of nutrients and medicinal properties.

Marble Art Studio said...

Corian Mandir design offers a modern yet traditional aesthetic to your sacred space. Crafted from durable Corian material, these mandirs provide a sleek, seamless look that enhances the beauty of any home. With customizable designs and colors, a Corian Mandir design brings elegance and spiritual serenity to your living space, perfectly blending style with devotion.