How to read cookie from Windows Application C#?

Posted by Sundermagar under C# on 10/2/2010 | Points: 10 | Views : 9252 | Status : [Member] | Replies : 6
Hi All,

Can anyone answer how to read cookie created in php from Windows application in C#.

Problem: I am writing a cookie name [userid] in php. Now I want to access cookie [userid] in my windows application which is in C#.

Thanks,
Sunder

Sunder Magar


Responses

Posted by: SheoNarayan on: 10/2/2010 [Administrator] HonoraryPlatinum | Points: 25

Up
0
Down
I think irrespective of cookie being written in PHP or ASP.NET, you can access the cookies for different program but accessing the cookie in windows application is little strange, what is your requirement? Can you explain and why you need to access it into windows?

Irrespective of what is your purpose this article can help you http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest.cookiecontainer.aspx

Thanks

Regards,
Sheo Narayan
http://www.dotnetfunda.com

Sundermagar, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Vuyiswamb on: 10/3/2010 [Member] [MVP] [Administrator] NotApplicable | Points: 25

Up
0
Down
Good Day Sundermagar

This is a bit strange for me, But anyway this is how its done
http://msdn.microsoft.com/en-us/library/system.windows.application.getcookie.aspx

Thank you for posting at Dotnetfunda

Vuyiswa Maseko

Thank you for posting at Dotnetfunda
[Administrator]

Sundermagar, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sundermagar on: 10/5/2010 [Member] Starter | Points: 25

Up
0
Down
Hi Seo,

Thanks for your reply!!

The problem is something like this:

I am consuming a webservice running in PHP through a Windows application which uploads the contacts from outlook like facebook finder. Now I want to restricts user to run application only those who has logged in to the website. for that i am creating a cookie on login.

Now I want to check when windows apps runs if the cookie is present then I will get the userid and upload the contacts to respective users account.

Thanks,
Sunder

Sunder Magar

Sundermagar, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: SheoNarayan on: 10/6/2010 [Administrator] HonoraryPlatinum | Points: 25

Up
0
Down
Thanks Sunder,

Did you try above link to access the cookies?

I hope those links will help you.

Thanks

Regards,
Sheo Narayan
http://www.dotnetfunda.com

Sundermagar, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sundermagar on: 10/6/2010 [Member] Starter | Points: 25

Up
0
Down
Hi Sheo,

Your solutions is perfect but I have an issue accessing the cookie with this. Let me clear understand the scenario.

1. Login into php application. On login I am creating cookie named 'userid'
2. From win app I am creating webrequest with the same URL of login page. But I am not getting that cookie 'userid' I only get PHPSSID which is i think the application session id.

Ex:

Login URL www.demourl.com/login.php
Once logged in generating webrequest from win app
www.demourl.com/login.php.

Please let me know if you have any deeper idea. It would be really helpful for me.

Thanks,
Sunder

Sunder Magar

Sundermagar, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sundermagar on: 10/6/2010 [Member] Starter | Points: 25

Up
0
Down
Hi Sheo,

After fighting with the issue I reached to conclusion that because My cookie is setting after user logged in so I am not able to get the cookie through WebRequest.

Once I logged in I set the cookie but again I am creating a Webrequest which means its a new request to the server so it will ask for the credentials to set the cookie which is not supplied so cookie will not get into webrequest.

Now I thought of reading Cookie from local machine all the cookie from local machine. do you have any idea how to read cookie from local machine using C# in windows application?

Thanks,
Sunder

Sunder Magar

Sundermagar, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response