Calyptus.Mvc.ForceHostAttribute.OnBeforeAction C# (CSharp) Method

OnBeforeAction() public method

public OnBeforeAction ( IHttpContext context, BeforeActionEventArgs args ) : void
context IHttpContext
args BeforeActionEventArgs
return void
		public void OnBeforeAction(IHttpContext context, BeforeActionEventArgs args)
		{
			Uri uri = context.Request.Url;
			bool hostAccepted = false;
			foreach (string host in Hosts)
				if (host != null && host.Equals(uri.Host, StringComparison.CurrentCultureIgnoreCase))
				{
					hostAccepted = true;
					break;
				}
			if ((Port > 0 && uri.Port != Port) || !hostAccepted)
			{
				if (context.Request.RequestType != "GET")
					return; // Skip for none GET requests which can't be redirected

				int port = Port > 0 ? Port : uri.Port;
				string host = hostAccepted ? uri.Host : Hosts[0];
				throw new Redirect((context.Request.IsSecureConnection ? "https://" : "http://") + host + (port != (context.Request.IsSecureConnection ? 443 : 80) ? ":" + Port.ToString() : null) + uri.PathAndQuery, true);
			}
		}