www.dilella.org

“the only source of knowledge is experience” – Albert Einstein

Archive for the ‘c#’ Category

HTTP Cookies with .NET

"HTTP cookies, sometimes known as web cookies or just cookies, are parcels of text sent by a server to a web browser and then sent back unchanged by the browser each time it accesses that server. HTTP cookies are used for authenticating, tracking, and maintaining specific information about users, such as site preferences and the contents of their electronic shopping carts. The term "cookie" is derived from "magic cookie," a well-known concept in Unix computing which inspired both the idea and the name of HTTP cookies." – en.wikipedia.org

If you want to store and reuse cookies within .NET you need to use the cookiecontainer. Here is an example on how to work with http cookies under .NET:

HTTP Request :: Store the cookie

wr = WebRequest.Create(uri);
wr.Method = "POST";

HttpWebRequest hwr = (HttpWebRequest)wr;
hwr.CookieContainer = new CookieContainer();

HttpWebResponse httpResponse = (HttpWebResponse)wr.GetResponse();
if (httpResponse.StatusCode == System.Net.HttpStatusCode.OK)
{
     // *** Save the cookies on the persistent object
     if (httpResponse.Cookies.Count > 0)
        this.Cookies = httpResponse.Cookies;
}


HTTP Request :: Use the cookies that have been stored before

wr = WebRequest.Create(uri);
wr.Method = "GET";

((HttpWebRequest)wr).CookieContainer = new CookieContainer();
if (this.Cookies != null &&
   this.Cookies.Count > 0)
      ((HttpWebRequest)wr).CookieContainer.Add(this.Cookies);

HttpWebResponse httpResponse = (HttpWebResponse)wr.GetResponse();
if (httpResponse.StatusCode == System.Net.HttpStatusCode.OK)
{
}

  • Share/Bookmark
  • 0 Comments
  • Filed under: Coding, c#
  • Newtonsoft Json.NET

    From the readme.txt:

    "The Json.NET library allows the simple and safe reading and writing of JSON objects from .NET. Using readers and writers, similar to .NET’s XML API, Json.NET will be familiar to most .NET developers and makes passing messages between .NET and JavaScript a snap.

    Copyright 2006 James Newton-King
    http://www.newtonsoft.com

    This work is licensed under the Creative Commons Attribution 2.5 License
    http://creativecommons.org/licenses/by/2.5/

    You are free:
       * to copy, distribute, display, and perform the work
       * to make derivative works
       * to make commercial use of the work"

    You can download it here: http://www.newtonsoft.com/products/json/

     

    • Share/Bookmark
  • Comments Off
  • Filed under: Coding, c#, libraries
  • Collection of good C# links

    Books:

    • http://www.galileocomputing.de/openbook/csharp/
    • http://www.galileocomputing.de/openbook/visual_csharp/
    • http://www.guidetocsharp.de
    • http://www.publicjoe.co.uk/csharp/samples/ebook.html
    • http://apress.com/free/content/Dissecting_A_CSharp_Application.pdf
    • http://www.programmersheaven.com/ebooks/csharp_ebook.pdf

    Articles/Help:

    • http://www.c-sharpcorner.com/
    • http://www.codeproject.com/csharp/
    • http://www.csharphelp.com/
    • http://www.aspheute.com/kategorien/Csharp.htm
    • http://dotnet-snippets.de/dns/default.aspx
    • http://www.it-visions.de/dotnet/components.aspx
    • http://dotnet-magazin.de/
    • http://www.dotnetgerman.com/
    • http://www.gotdotnet.com/
    • http://www.c-sharp-forum.de/
    • http://www.mycsharp.de/wbb2/
    • http://www.albahari.com/threading/
    • http://www.c-plusplus.de/forum/viewforum-var-f-is-28.html
    • http://entwickler-forum.de/forumdisplay.php?f=7
    • http://www.yoda.arachsys.com/csharp/index.html

    The list will be updated …

    • Share/Bookmark
  • Comments Off
  • Filed under: Coding, c#