locked
cookie not working in windows service application RRS feed

  • Question

  • When trying to use cookie in windows service application i am getting an error "change.System.NullReferenceException: Object reference not set to an instance of an object. "

    This is the code i am trying to use "HttpContext.Current.Request.Cookies["yourInfo"].Value.ToString() != string.Empty "

     

    Any help is greatly appreciated
    • Moved by spacewrangler Monday, November 29, 2010 8:24 PM (From:Building Development and Diagnostic Tools for .Net)
    Monday, November 29, 2010 2:22 PM

Answers

  • I understood that i cant use cookie or caching in windows service app.

    Could you please help me how can i store a value for 30 minutes for windows service application?


    Hi Pericherla,

    Why do you want to use windows Service to store the value? you can store the value to a file from webservice then get the value again after 30 minutes and compare the value.

    Have a nice day.

    Alan Chen

    • Marked as answer by Alan_chen Wednesday, December 8, 2010 2:07 AM
    Friday, December 3, 2010 3:37 AM

All replies


  • HttpContext is a class for getting the current request server side, often within a DLL as the service front code would have the context already.  You mentioned you are trying to use a cookie in a windows service.  Did you really mean a Web service?  That would make more sense if you were trying to do this in a web service.  In a windows service, it would not make sense to use the code you posted.

    --
    Mike
    Monday, November 29, 2010 11:44 PM
  • I am trying to use in windows service not web service.

    if i use "Request.Cookies["yourInfo"].Value.ToString()" i am getting Error  "The name 'Request' does not exist in the current context"

    but if i use same thing in web app i dont see any error.

    i am trying to save a value in cookie which i test after 30 mins and see if it has same vale that coming from web service

    Could you please help if is there any namespace or code that i needed

    Tuesday, November 30, 2010 1:26 PM
  • I understood that i cant use cookie or caching in windows service app.

    Could you please help me how can i store a value for 30 minutes for windows service application?

    Tuesday, November 30, 2010 3:09 PM
  • Oh, I see...
     
    Client side, you would be using HttpWebRequest.CookieContainer, as shown in the example here:  http://msdn.microsoft.com/en-us/library/system.net..httpwebrequest.cookiecontainer.aspx

     

    --
    Mike
    Tuesday, November 30, 2010 11:29 PM
  • I understood that i cant use cookie or caching in windows service app.

    Could you please help me how can i store a value for 30 minutes for windows service application?


    Hi Pericherla,

    Why do you want to use windows Service to store the value? you can store the value to a file from webservice then get the value again after 30 minutes and compare the value.

    Have a nice day.

    Alan Chen

    • Marked as answer by Alan_chen Wednesday, December 8, 2010 2:07 AM
    Friday, December 3, 2010 3:37 AM