5cc10b82aea12bf43cd6e89573d7342dc1552111
[mono.git] / mcs / class / System.Web / System.Web.Security / FormsAuthentication.cs
1 //
2 // System.Web.Security.FormsAuthentication
3 //
4 // Authors:
5 //      Gonzalo Paniagua Javier (gonzalo@ximian.com)
6 //
7 // (C) 2002,2003 Ximian, Inc (http://www.ximian.com)
8 // Copyright (c) 2005 Novell, Inc (http://www.novell.com)
9 //
10
11 //
12 // Permission is hereby granted, free of charge, to any person obtaining
13 // a copy of this software and associated documentation files (the
14 // "Software"), to deal in the Software without restriction, including
15 // without limitation the rights to use, copy, modify, merge, publish,
16 // distribute, sublicense, and/or sell copies of the Software, and to
17 // permit persons to whom the Software is furnished to do so, subject to
18 // the following conditions:
19 // 
20 // The above copyright notice and this permission notice shall be
21 // included in all copies or substantial portions of the Software.
22 // 
23 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
27 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
28 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
29 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30 //
31
32 using System.Collections;
33 using System.IO;
34 using System.Security.Cryptography;
35 using System.Security.Permissions;
36 using System.Text;
37 using System.Web;
38 using System.Web.Configuration;
39 using System.Web.Util;
40 using System.Globalization;
41
42 namespace System.Web.Security
43 {
44         // CAS - no InheritanceDemand here as the class is sealed
45         [AspNetHostingPermission (SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
46         public sealed class FormsAuthentication
47         {
48                 const int MD5_hash_size = 16;
49                 const int SHA1_hash_size = 20;
50
51                 static string authConfigPath = "system.web/authentication";
52                 static string machineKeyConfigPath = "system.web/machineKey";
53 #if TARGET_J2EE
54                 const string Forms_initialized = "Forms.initialized";
55                 const string Forms_cookieName = "Forms.cookieName";
56                 const string Forms_cookiePath = "Forms.cookiePath";
57                 const string Forms_timeout = "Forms.timeout";
58                 const string Forms_protection = "Forms.protection";
59                 const string Forms_init_vector = "Forms.init_vector";
60                 static bool initialized
61                 {
62                         get {
63                                 object o = AppDomain.CurrentDomain.GetData (Forms_initialized);
64                                 return o != null ? (bool) o : false;
65                         }
66                         set { AppDomain.CurrentDomain.SetData (Forms_initialized, value); }
67                 }
68                 static string cookieName
69                 {
70                         get { return (string) AppDomain.CurrentDomain.GetData (Forms_cookieName); }
71                         set { AppDomain.CurrentDomain.SetData (Forms_cookieName, value); }
72                 }
73                 static string cookiePath
74                 {
75                         get { return (string) AppDomain.CurrentDomain.GetData (Forms_cookiePath); }
76                         set { AppDomain.CurrentDomain.SetData (Forms_cookiePath, value); }
77                 }
78                 static int timeout
79                 {
80                         get {
81                                 object o = AppDomain.CurrentDomain.GetData (Forms_timeout);
82                                 return o != null ? (int) o : 0;
83                         }
84                         set { AppDomain.CurrentDomain.SetData (Forms_timeout, value); }
85                 }
86                 static FormsProtectionEnum protection
87                 {
88                         get { return (FormsProtectionEnum) AppDomain.CurrentDomain.GetData (Forms_protection); }
89                         set { AppDomain.CurrentDomain.SetData (Forms_protection, value); }
90                 }
91                 static byte [] init_vector
92                 {
93                         get { return (byte []) AppDomain.CurrentDomain.GetData (Forms_init_vector); }
94                         set { AppDomain.CurrentDomain.SetData (Forms_init_vector, value); }
95                 }
96                 static object locker = new object ();
97 #else
98                 static bool initialized;
99                 static string cookieName;
100                 static string cookiePath;
101                 static int timeout;
102                 static FormsProtectionEnum protection;
103                 static object locker = new object ();
104                 static byte [] init_vector; // initialization vector used for 3DES
105 #endif
106 #if NET_1_1
107 #if TARGET_J2EE
108                 const string Forms_requireSSL = "Forms.requireSSL";
109                 const string Forms_slidingExpiration = "Forms.slidingExpiration";
110
111                 static bool requireSSL
112                 {
113                         get {
114                                 object o = AppDomain.CurrentDomain.GetData (Forms_requireSSL);
115                                 return o != null ? (bool) o : false;
116                         }
117                         set { AppDomain.CurrentDomain.SetData (Forms_requireSSL, value); }
118                 }
119                 static bool slidingExpiration
120                 {
121                         get {
122                                 object o = AppDomain.CurrentDomain.GetData (Forms_slidingExpiration);
123                                 return o != null ? (bool) o : false;
124                         }
125                         set { AppDomain.CurrentDomain.SetData (Forms_slidingExpiration, value); }
126                 }
127 #else
128                 static bool requireSSL;
129                 static bool slidingExpiration;
130 #endif
131 #endif
132 #if NET_2_0
133 #if TARGET_J2EE
134                 const string Forms_cookie_domain = "Forms.cookie_domain";
135                 const string Forms_cookie_mode = "Forms.cookie_mode";
136                 const string Forms_cookies_supported = "Forms.cookies_supported";
137                 const string Forms_default_url = "Forms.default_url";
138                 const string Forms_enable_crossapp_redirects = "Forms.enable_crossapp_redirects";
139                 const string Forms_login_url = "Forms.login_url";
140                 static string cookie_domain
141                 {
142                         get { return (string) AppDomain.CurrentDomain.GetData (Forms_cookie_domain); }
143                         set { AppDomain.CurrentDomain.SetData (Forms_cookie_domain, value); }
144                 }
145                 static HttpCookieMode cookie_mode
146                 {
147                         get { return (HttpCookieMode) AppDomain.CurrentDomain.GetData (Forms_cookie_mode); }
148                         set { AppDomain.CurrentDomain.SetData (Forms_cookie_mode, value); }
149                 }
150                 static bool cookies_supported
151                 {
152                         get {
153                                 object o = AppDomain.CurrentDomain.GetData (Forms_cookies_supported);
154                                 return o != null ? (bool) o : false;
155                         }
156                         set { AppDomain.CurrentDomain.SetData (Forms_cookies_supported, value); }
157                 }
158                 static string default_url
159                 {
160                         get { return (string) AppDomain.CurrentDomain.GetData (Forms_default_url); }
161                         set { AppDomain.CurrentDomain.SetData (Forms_default_url, value); }
162                 }
163                 static bool enable_crossapp_redirects
164                 {
165                         get {
166                                 object o = AppDomain.CurrentDomain.GetData (Forms_enable_crossapp_redirects);
167                                 return o != null ? (bool) o : false;
168                         }
169                         set { AppDomain.CurrentDomain.SetData (Forms_enable_crossapp_redirects, value); }
170                 }
171                 static string login_url
172                 {
173                         get { return (string) AppDomain.CurrentDomain.GetData (Forms_login_url); }
174                         set { AppDomain.CurrentDomain.SetData (Forms_login_url, value); }
175                 }
176 #else
177                 static string cookie_domain;
178                 static HttpCookieMode cookie_mode;
179                 static bool cookies_supported;
180                 static string default_url;
181                 static bool enable_crossapp_redirects;
182                 static string login_url;
183 #endif
184 #endif
185                 // same names and order used in xsp
186                 static string [] indexFiles = { "index.aspx",
187                                                 "Default.aspx",
188                                                 "default.aspx",
189                                                 "index.html",
190                                                 "index.htm" };
191
192                 public FormsAuthentication ()
193                 {
194                 }
195
196                 public static bool Authenticate (string name, string password)
197                 {
198                         if (name == null || password == null)
199                                 return false;
200
201                         Initialize ();
202                         HttpContext context = HttpContext.Current;
203                         if (context == null)
204                                 throw new HttpException ("Context is null!");
205
206 #if NET_2_0
207                         AuthenticationSection section = (AuthenticationSection) WebConfigurationManager.GetSection (authConfigPath);
208                         FormsAuthenticationCredentials config = section.Forms.Credentials;
209                         FormsAuthenticationUser user = config.Users[name];
210                         string stored = null;
211
212                         if (user != null)
213                                 stored = user.Password;
214 #else
215                         AuthConfig config = context.GetConfig (authConfigPath) as AuthConfig;
216                         Hashtable users = config.CredentialUsers;
217                         string stored = users [name] as string;
218 #endif
219                         if (stored == null)
220                                 return false;
221
222                         switch (config.PasswordFormat) {
223                         case FormsAuthPasswordFormat.Clear:
224                                 /* Do nothing */
225                                 break;
226                         case FormsAuthPasswordFormat.MD5:
227                                 password = HashPasswordForStoringInConfigFile (password, "MD5");
228                                 break;
229                         case FormsAuthPasswordFormat.SHA1:
230                                 password = HashPasswordForStoringInConfigFile (password, "SHA1");
231                                 break;
232                         }
233
234                         return (password == stored);
235                 }
236
237                 static FormsAuthenticationTicket Decrypt2 (byte [] bytes)
238                 {
239                         if (protection == FormsProtectionEnum.None)
240                                 return FormsAuthenticationTicket.FromByteArray (bytes);
241
242 #if NET_2_0
243                         MachineKeySection config = (MachineKeySection) WebConfigurationManager.GetSection (machineKeyConfigPath);
244 #else
245                         MachineKeyConfig config = HttpContext.GetAppConfig (machineKeyConfigPath) as MachineKeyConfig;
246 #endif
247                         bool all = (protection == FormsProtectionEnum.All);
248
249                         byte [] result = bytes;
250                         if (all || protection == FormsProtectionEnum.Encryption) {
251                                 ICryptoTransform decryptor;
252                                 decryptor = TripleDES.Create ().CreateDecryptor (config.DecryptionKey192Bits, init_vector);
253                                 result = decryptor.TransformFinalBlock (bytes, 0, bytes.Length);
254                                 bytes = null;
255                         }
256
257                         if (all || protection == FormsProtectionEnum.Validation) {
258                                 int count;
259                                 MachineKeyValidation validationType;
260
261 #if NET_2_0
262                                 validationType = config.Validation;
263 #else
264                                 validationType = config.ValidationType;
265 #endif
266                                 if (validationType == MachineKeyValidation.MD5)
267                                         count = MD5_hash_size;
268                                 else
269                                         count = SHA1_hash_size; // 3DES and SHA1
270
271 #if NET_2_0
272                                 byte [] vk = config.ValidationKeyBytes;
273 #else
274                                 byte [] vk = config.ValidationKey;
275 #endif
276                                 byte [] mix = new byte [result.Length - count + vk.Length];
277                                 Buffer.BlockCopy (result, 0, mix, 0, result.Length - count);
278                                 Buffer.BlockCopy (vk, 0, mix, result.Length - count, vk.Length);
279
280                                 byte [] hash = null;
281                                 switch (validationType) {
282                                 case MachineKeyValidation.MD5:
283                                         hash = MD5.Create ().ComputeHash (mix);
284                                         break;
285                                 // From MS docs: "When 3DES is specified, forms authentication defaults to SHA1"
286                                 case MachineKeyValidation.TripleDES:
287                                 case MachineKeyValidation.SHA1:
288                                         hash = SHA1.Create ().ComputeHash (mix);
289                                         break;
290                                 }
291
292                                 if (result.Length < count)
293                                         throw new ArgumentException ("Error validating ticket (length).", "encryptedTicket");
294
295                                 int i, k;
296                                 for (i = result.Length - count, k = 0; k < count; i++, k++) {
297                                         if (result [i] != hash [k])
298                                                 throw new ArgumentException ("Error validating ticket.", "encryptedTicket");
299                                 }
300                         }
301
302                         return FormsAuthenticationTicket.FromByteArray (result);
303                 }
304
305                 public static FormsAuthenticationTicket Decrypt (string encryptedTicket)
306                 {
307                         if (encryptedTicket == null || encryptedTicket == String.Empty)
308                                 throw new ArgumentException ("Invalid encrypted ticket", "encryptedTicket");
309
310                         Initialize ();
311
312                         FormsAuthenticationTicket ticket;
313 #if NET_2_0
314                         byte [] bytes = MachineKeySection.GetBytes (encryptedTicket, encryptedTicket.Length);
315 #else
316                         byte [] bytes = MachineKeyConfig.GetBytes (encryptedTicket, encryptedTicket.Length);
317 #endif
318                         try {
319                                 ticket = Decrypt2 (bytes);
320                         } catch (Exception) {
321                                 ticket = null;
322                         }
323
324                         return ticket;
325                 }
326
327                 public static string Encrypt (FormsAuthenticationTicket ticket)
328                 {
329                         if (ticket == null)
330                                 throw new ArgumentNullException ("ticket");
331
332                         Initialize ();
333                         byte [] ticket_bytes = ticket.ToByteArray ();
334                         if (protection == FormsProtectionEnum.None)
335                                 return GetHexString (ticket_bytes);
336
337                         byte [] result = ticket_bytes;
338 #if NET_2_0
339                         MachineKeySection config = (MachineKeySection) WebConfigurationManager.GetSection (machineKeyConfigPath);
340 #else
341                         MachineKeyConfig config = HttpContext.GetAppConfig (machineKeyConfigPath) as MachineKeyConfig;
342 #endif
343                         bool all = (protection == FormsProtectionEnum.All);
344                         if (all || protection == FormsProtectionEnum.Validation) {
345                                 byte [] valid_bytes = null;
346 #if NET_2_0
347                                 byte [] vk = config.ValidationKeyBytes;
348 #else
349                                 byte [] vk = config.ValidationKey;
350 #endif
351                                 byte [] mix = new byte [ticket_bytes.Length + vk.Length];
352                                 Buffer.BlockCopy (ticket_bytes, 0, mix, 0, ticket_bytes.Length);
353                                 Buffer.BlockCopy (vk, 0, mix, result.Length, vk.Length);
354
355                                 switch (
356 #if NET_2_0
357                                         config.Validation
358 #else
359                                         config.ValidationType
360 #endif
361                                         ) {
362                                 case MachineKeyValidation.MD5:
363                                         valid_bytes = MD5.Create ().ComputeHash (mix);
364                                         break;
365                                 // From MS docs: "When 3DES is specified, forms authentication defaults to SHA1"
366                                 case MachineKeyValidation.TripleDES:
367                                 case MachineKeyValidation.SHA1:
368                                         valid_bytes = SHA1.Create ().ComputeHash (mix);
369                                         break;
370                                 }
371
372                                 int tlen = ticket_bytes.Length;
373                                 int vlen = valid_bytes.Length;
374                                 result = new byte [tlen + vlen];
375                                 Buffer.BlockCopy (ticket_bytes, 0, result, 0, tlen);
376                                 Buffer.BlockCopy (valid_bytes, 0, result, tlen, vlen);
377                         }
378
379                         if (all || protection == FormsProtectionEnum.Encryption) {
380                                 ICryptoTransform encryptor;
381                                 encryptor = TripleDES.Create ().CreateEncryptor (config.DecryptionKey192Bits, init_vector);
382                                 result = encryptor.TransformFinalBlock (result, 0, result.Length);
383                         }
384
385                         return GetHexString (result);
386                 }
387
388                 public static HttpCookie GetAuthCookie (string userName, bool createPersistentCookie)
389                 {
390                         return GetAuthCookie (userName, createPersistentCookie, null);
391                 }
392
393                 public static HttpCookie GetAuthCookie (string userName, bool createPersistentCookie, string strCookiePath)
394                 {
395                         Initialize ();
396
397                         if (userName == null)
398                                 userName = String.Empty;
399
400                         if (strCookiePath == null || strCookiePath.Length == 0)
401                                 strCookiePath = cookiePath;
402
403                         DateTime now = DateTime.Now;
404                         DateTime then;
405                         if (createPersistentCookie)
406                                 then = now.AddYears (50);
407                         else
408                                 then = now.AddMinutes (timeout);
409
410                         FormsAuthenticationTicket ticket = new FormsAuthenticationTicket (1,
411                                                                                           userName,
412                                                                                           now,
413                                                                                           then,
414                                                                                           createPersistentCookie,
415                                                                                           String.Empty,
416                                                                                           cookiePath);
417
418                         if (!createPersistentCookie)
419                                 then = DateTime.MinValue;
420
421                         HttpCookie cookie = new HttpCookie (cookieName, Encrypt (ticket), strCookiePath, then);
422                         if (requireSSL)
423                                 cookie.Secure = true;
424                         return cookie;
425                 }
426
427                 internal static string ReturnUrl
428                 {
429                         get { return HttpContext.Current.Request ["RETURNURL"]; }
430                 }
431
432                 public static string GetRedirectUrl (string userName, bool createPersistentCookie)
433                 {
434                         if (userName == null)
435                                 return null;
436
437                         Initialize ();
438                         HttpRequest request = HttpContext.Current.Request;
439                         string returnUrl = ReturnUrl;
440                         if (returnUrl != null)
441                                 return returnUrl;
442
443                         returnUrl = request.ApplicationPath;
444                         string apppath = request.PhysicalApplicationPath;
445                         bool found = false;
446
447                         foreach (string indexFile in indexFiles) {
448                                 string filePath = Path.Combine (apppath, indexFile);
449                                 if (File.Exists (filePath)) {
450                                         returnUrl = UrlUtils.Combine (returnUrl, indexFile);
451                                         found = true;
452                                         break;
453                                 }
454                         }
455
456                         if (!found)
457                                 returnUrl = UrlUtils.Combine (returnUrl, "index.aspx");
458
459                         return returnUrl;
460                 }
461
462                 static string GetHexString (byte [] bytes)
463                 {
464                         StringBuilder result = new StringBuilder (bytes.Length * 2);
465                         foreach (byte b in bytes)
466                                 result.AppendFormat ("{0:X2}", (int) b);
467
468                         return result.ToString ();
469                 }
470
471                 public static string HashPasswordForStoringInConfigFile (string password, string passwordFormat)
472                 {
473                         if (password == null)
474                                 throw new ArgumentNullException ("password");
475
476                         if (passwordFormat == null)
477                                 throw new ArgumentNullException ("passwordFormat");
478
479                         byte [] bytes;
480                         if (String.Compare (passwordFormat, "MD5", true, CultureInfo.InvariantCulture) == 0) {
481                                 bytes = MD5.Create ().ComputeHash (Encoding.UTF8.GetBytes (password));
482                         } else if (String.Compare (passwordFormat, "SHA1", true, CultureInfo.InvariantCulture) == 0) {
483                                 bytes = SHA1.Create ().ComputeHash (Encoding.UTF8.GetBytes (password));
484                         } else {
485                                 throw new ArgumentException ("The format must be either MD5 or SHA1", "passwordFormat");
486                         }
487
488                         return GetHexString (bytes);
489                 }
490
491                 public static void Initialize ()
492                 {
493                         if (initialized)
494                                 return;
495
496                         lock (locker) {
497                                 if (initialized)
498                                         return;
499
500 #if NET_2_0
501                                 AuthenticationSection section = (AuthenticationSection)WebConfigurationManager.GetSection (authConfigPath);
502                                 FormsAuthenticationConfiguration config = section.Forms;
503
504                                 cookieName = config.Name;
505                                 timeout = (int)config.Timeout.TotalMinutes;
506                                 cookiePath = config.Path;
507                                 protection = config.Protection;
508                                 requireSSL = config.RequireSSL;
509                                 slidingExpiration = config.SlidingExpiration;
510                                 cookie_domain = config.Domain;
511                                 cookie_mode = config.Cookieless;
512                                 cookies_supported = true; /* XXX ? */
513                                 default_url = MapUrl(config.DefaultUrl);
514                                 enable_crossapp_redirects = config.EnableCrossAppRedirects;
515                                 login_url = MapUrl(config.LoginUrl);
516 #else
517                                 HttpContext context = HttpContext.Current;
518                                 AuthConfig authConfig = context.GetConfig (authConfigPath) as AuthConfig;
519                                 if (authConfig != null) {
520                                         cookieName = authConfig.CookieName;
521                                         timeout = authConfig.Timeout;
522                                         cookiePath = authConfig.CookiePath;
523                                         protection = authConfig.Protection;
524 #if NET_1_1
525                                         requireSSL = authConfig.RequireSSL;
526                                         slidingExpiration = authConfig.SlidingExpiration;
527 #endif
528                                 } else {
529                                         cookieName = ".MONOAUTH";
530                                         timeout = 30;
531                                         cookiePath = "/";
532                                         protection = FormsProtectionEnum.All;
533 #if NET_1_1
534                                         slidingExpiration = true;
535 #endif
536                                 }
537 #endif
538
539                                 // IV is 8 bytes long for 3DES
540                                 init_vector = new byte [8];
541                                 int len = cookieName.Length;
542                                 for (int i = 0; i < 8; i++) {
543                                         if (i >= len)
544                                                 break;
545
546                                         init_vector [i] = (byte) cookieName [i];
547                                 }
548
549                                 initialized = true;
550                         }
551                 }
552
553 #if NET_2_0
554                 static string MapUrl (string url) {
555                         if (UrlUtils.IsRelativeUrl (url))
556                                 return UrlUtils.Combine (HttpRuntime.AppDomainAppVirtualPath, url);
557                         else
558                                 return UrlUtils.ResolveVirtualPathFromAppAbsolute (url);
559                 }
560 #endif
561
562                 public static void RedirectFromLoginPage (string userName, bool createPersistentCookie)
563                 {
564                         RedirectFromLoginPage (userName, createPersistentCookie, null);
565                 }
566
567                 public static void RedirectFromLoginPage (string userName, bool createPersistentCookie, string strCookiePath)
568                 {
569                         if (userName == null)
570                                 return;
571
572                         Initialize ();
573                         SetAuthCookie (userName, createPersistentCookie, strCookiePath);
574                         Redirect (GetRedirectUrl (userName, createPersistentCookie), false);
575                 }
576
577                 public static FormsAuthenticationTicket RenewTicketIfOld (FormsAuthenticationTicket tOld)
578                 {
579                         if (tOld == null)
580                                 return null;
581
582                         DateTime now = DateTime.Now;
583                         TimeSpan toIssue = now - tOld.IssueDate;
584                         TimeSpan toExpiration = tOld.Expiration - now;
585                         if (toExpiration > toIssue)
586                                 return tOld;
587
588                         FormsAuthenticationTicket tNew = tOld.Clone ();
589                         tNew.SetDates (now, now + (tOld.Expiration - tOld.IssueDate));
590                         return tNew;
591                 }
592
593                 public static void SetAuthCookie (string userName, bool createPersistentCookie)
594                 {
595                         Initialize ();
596                         SetAuthCookie (userName, createPersistentCookie, cookiePath);
597                 }
598
599                 public static void SetAuthCookie (string userName, bool createPersistentCookie, string strCookiePath)
600                 {
601                         HttpContext context = HttpContext.Current;
602                         if (context == null)
603                                 throw new HttpException ("Context is null!");
604
605                         HttpResponse response = context.Response;
606                         if (response == null)
607                                 throw new HttpException ("Response is null!");
608
609                         response.Cookies.Add (GetAuthCookie (userName, createPersistentCookie, strCookiePath));
610                 }
611
612                 public static void SignOut ()
613                 {
614                         Initialize ();
615
616                         HttpContext context = HttpContext.Current;
617                         if (context == null)
618                                 throw new HttpException ("Context is null!");
619
620                         HttpResponse response = context.Response;
621                         if (response == null)
622                                 throw new HttpException ("Response is null!");
623
624                         HttpCookieCollection cc = response.Cookies;
625                         cc.Remove (cookieName);
626                         HttpCookie expiration_cookie = new HttpCookie (cookieName, "");
627                         expiration_cookie.Expires = new DateTime (1999, 10, 12);
628                         expiration_cookie.Path = cookiePath;
629                         cc.Add (expiration_cookie);
630
631 #if NET_2_0
632                         Roles.DeleteCookie ();
633 #endif
634                 }
635
636                 public static string FormsCookieName
637                 {
638                         get {
639                                 Initialize ();
640                                 return cookieName;
641                         }
642                 }
643
644                 public static string FormsCookiePath
645                 {
646                         get {
647                                 Initialize ();
648                                 return cookiePath;
649                         }
650                 }
651 #if NET_1_1
652                 public static bool RequireSSL {
653                         get {
654                                 Initialize ();
655                                 return requireSSL;
656                         }
657                 }
658
659                 public static bool SlidingExpiration {
660                         get {
661                                 Initialize ();
662                                 return slidingExpiration;
663                         }
664                 }
665 #endif
666
667 #if NET_2_0
668                 public static string CookieDomain {
669                         get { Initialize (); return cookie_domain; }
670                 }
671
672                 public static HttpCookieMode CookieMode {
673                         get { Initialize (); return cookie_mode; }
674                 }
675
676                 public static bool CookiesSupported {
677                         get { Initialize (); return cookies_supported; }
678                 }
679
680                 public static string DefaultUrl {
681                         get { Initialize (); return default_url; }
682                 }
683
684                 public static bool EnableCrossAppRedirects {
685                         get { Initialize (); return enable_crossapp_redirects; }
686                 }
687
688                 public static string LoginUrl {
689                         get { Initialize (); return login_url; }
690                 }
691
692                 public static void RedirectToLoginPage ()
693                 {
694                         Redirect (LoginUrl);
695                 }
696
697                 [MonoTODO ("needs more tests")]
698                 public static void RedirectToLoginPage (string extraQueryString)
699                 {
700                         // TODO: if ? is in LoginUrl (legal?), ? in query (legal?) ...
701                         Redirect (LoginUrl + "?" + extraQueryString);
702                 }
703
704                 private static void Redirect (string url)
705                 {
706                         HttpContext.Current.Response.Redirect (url);
707                 }
708 #endif
709
710                 private static void Redirect (string url, bool end)
711                 {
712                         HttpContext.Current.Response.Redirect (url, end);
713                 }
714         }
715 }