C# Masaüstü uygulamada Cookie Örneği
4
●2.905
- 27-08-2010, 09:12:18Kimlik doğrulama veya yönetimden onay bekliyor.Normalde win application cookie desteklemez. Eğer farklı bir amacınız varsa msdn'den aldığım kod işinize yarayabilir.
Msdn'den bir örnek:
[C#] using System.Net; using System; namespace Examples.System.Net.Cookies { // This example is run at the command line. // Specify one argument: the name of the host to // send the request to. // If the request is sucessful, the example displays the contents of the cookies // returned by the host. public class CookieExample { public static void Main(string[] args) { if (args == null || args.Length != 1) { Console.WriteLine("Specify the URL to receive the request."); Environment.Exit(1); } HttpWebRequest request = (HttpWebRequest)WebRequest.Create(args[0]); request.CookieContainer = new CookieContainer(); HttpWebResponse response = (HttpWebResponse) request.GetResponse(); response.Cookies = request.CookieContainer.GetCookies(request.RequestUri); // Print the properties of each cookie. foreach (Cookie cook in response.Cookies) { Console.WriteLine("Cookie:"); Console.WriteLine("{0} = {1}", cook.Name, cook.Value); Console.WriteLine("Domain: {0}", cook.Domain); Console.WriteLine("Path: {0}", cook.Path); Console.WriteLine("Port: {0}", cook.Port); Console.WriteLine("Secure: {0}", cook.Secure); Console.WriteLine("When issued: {0}", cook.TimeStamp); Console.WriteLine("Expires: {0} (expired? {1})", cook.Expires, cook.Expired); Console.WriteLine("Don't save: {0}", cook.Discard); Console.WriteLine("Comment: {0}", cook.Comment); Console.WriteLine("Uri for comments: {0}", cook.CommentUri); Console.WriteLine("Version: RFC {0}" , cook.Version == 1 ? "2109" : "2965"); // Show the string representation of the cookie. Console.WriteLine ("String: {0}", cook.ToString()); } } } } - 28-08-2010, 00:25:02Şu şekilde yapabilirsin.
İlk girişte db'den gerekli kontrolleri yaptığını varsayıyorum.
Guid UserID; UserID = (Guid)dtGetAccess.Rows[0]["id"]; frmMain Main = new frmMain(UserID);
frmMain girişten sonra gideceği form olsun.
Orda InitializeComponent(); ile gelen değeri alabilir ve kontrol edebilirsin tekrar.
public frmMain() { InitializeComponent(); } public frmMain(Guid _UserID) { InitializeComponent(); UserID = _UserID; }