Explorar o código

2005-11-28 Chris Toshok <[email protected]>

	* FormsAuthenticationModule.cs (OnAuthenticateRequest):
	CONFIGURATION_2_0 work.
	(OnEndRequest): same.


svn path=/trunk/mcs/; revision=53581
Chris Toshok %!s(int64=20) %!d(string=hai) anos
pai
achega
4ebea5593a

+ 6 - 0
mcs/class/System.Web/System.Web.Security/ChangeLog

@@ -1,3 +1,9 @@
+2005-11-28  Chris Toshok  <[email protected]>
+
+	* FormsAuthenticationModule.cs (OnAuthenticateRequest):
+	CONFIGURATION_2_0 work.
+	(OnEndRequest): same.
+
 2005-09-09  Sebastien Pouliot  <[email protected]>
 
 	* DefaultAuthenticationEventArgs.cs: Added LinkDemand for Minimal.

+ 33 - 6
mcs/class/System.Web/System.Web.Security/FormsAuthenticationModule.cs

@@ -58,17 +58,37 @@ namespace System.Web.Security
 		{
 			HttpApplication app = (HttpApplication) sender;
 			HttpContext context = app.Context;
+
+			string cookieName;
+			string cookiePath;
+			string loginPage;
+			bool slidingExpiration;
+
+#if CONFIGURATION_2_0
+			AuthenticationSection config = (AuthenticationSection) WebConfigurationManager.GetWebApplicationSection ("system.web/authentication");
+#else
 			AuthConfig config = (AuthConfig) context.GetConfig ("system.web/authentication");
+#endif
+
 			if (config == null || config.Mode != AuthenticationMode.Forms) {
 				return;
 			}
 
-			string cookieName = config.CookieName;
-			string cookiePath = config.CookiePath;
-			string loginPage = config.LoginUrl;
+#if CONFIGURATION_2_0
+			cookieName = config.Forms.Name;
+			cookiePath = config.Forms.Path;
+			loginPage = config.Forms.LoginUrl;
+			slidingExpiration = config.Forms.SlidingExpiration;
+#else
+			cookieName = config.CookieName;
+			cookiePath = config.CookiePath;
+			loginPage = config.LoginUrl;
+			slidingExpiration = config.SlidingExpiration;
+#endif
 
 			string reqPath = context.Request.PhysicalPath;
 			string loginPath = context.Request.MapPath (loginPage);
+
 			context.SkipAuthorization = (reqPath == loginPath);
 			
 			FormsAuthenticationEventArgs formArgs = new FormsAuthenticationEventArgs (context);
@@ -90,7 +110,7 @@ namespace System.Web.Security
 			if (ticket == null || (ticket.IsPersistent && ticket.Expired))
 				return;
 
-			if (config.SlidingExpiration)
+			if (slidingExpiration)
 				ticket = FormsAuthentication.RenewTicketIfOld (ticket);
 
 			context.User = new GenericPrincipal (new FormsIdentity (ticket), new string [0]);
@@ -110,12 +130,19 @@ namespace System.Web.Security
 			if (context.Response.StatusCode != 401 || context.Request.QueryString ["ReturnUrl"] != null)
 				return;
 
+			string loginPage;
+#if CONFIGURATION_2_0
+			AuthenticationSection config = (AuthenticationSection) WebConfigurationManager.GetWebApplicationSection ("system.web/authentication");
+			loginPage = config.Forms.LoginUrl;
+#else
 			AuthConfig config = (AuthConfig) context.GetConfig ("system.web/authentication");
-			if (config.Mode != AuthenticationMode.Forms)
+			loginPage = config.LoginUrl;
+#endif
+			if (config == null || config.Mode != AuthenticationMode.Forms)
 				return;
 
 			StringBuilder login = new StringBuilder ();
-			login.Append (UrlUtils.Combine (context.Request.ApplicationPath, config.LoginUrl));
+			login.Append (UrlUtils.Combine (context.Request.ApplicationPath, loginPage));
 			login.AppendFormat ("?ReturnUrl={0}", HttpUtility.UrlEncode (context.Request.RawUrl));
 			context.Response.Redirect (login.ToString ());
 		}