/// <summary>
        /// Follows external redirection through <c>umbracoRedirect</c> document property.
        /// </summary>
        /// <remarks>As per legacy, if the redirect does not work, we just ignore it.</remarks>
        private void FollowExternalRedirect()
        {
            if (_pcr.HasPublishedContent == false)
            {
                return;
            }

            // don't try to find a redirect if the property doesn't exist
            if (_pcr.PublishedContent.HasProperty(Constants.Conventions.Content.Redirect) == false)
            {
                return;
            }

            var redirectId = _pcr.PublishedContent.GetPropertyValue(Constants.Conventions.Content.Redirect, -1);

            var redirectUrl = "#";

            if (redirectId > 0)
            {
                redirectUrl = _routingContext.UrlProvider.GetUrl(redirectId);
            }
            else
            {
                // might be a UDI instead of an int Id
                var redirectUdi = _pcr.PublishedContent.GetPropertyValue <GuidUdi>(Constants.Conventions.Content.Redirect);
                if (redirectUdi != null)
                {
                    redirectUrl = _routingContext.UrlProvider.GetUrl(redirectUdi.Guid);
                }
            }
            if (redirectUrl != "#")
            {
                _pcr.SetRedirect(redirectUrl);
            }
        }
        public override bool TryFindContent(PublishedContentRequest contentRequest)
        {
            // Mobile logout
            if (contentRequest.Uri.AbsolutePath.Contains("for-members/login/logout=1"))
            {
                contentRequest.SetRedirect("/umbraco/Surface/MembersSurface/Logout");
                return true;
            }

            // 180 day Password Expiration Policy
            var member = Membership.GetUser();
            if (member != null && (DateTime.Now - member.LastPasswordChangedDate).TotalDays >= 180
                && !contentRequest.Uri.AbsoluteUri.Contains("your-account/change-password"))
            {
                contentRequest.SetRedirect("/your-account/change-password/");
                return true;
            }
            return base.TryFindContent(contentRequest);
        }
        private static bool TryRedirect(PublishedContentRequest contentRequest, bool includeQuery)
        {
            bool redirect = false;
            string path = string.Format("{0}{1}{2}", contentRequest.Uri.Authority
                                                   , contentRequest.Uri.AbsolutePath
                                                   , includeQuery ? contentRequest.Uri.Query : String.Empty
                                       );

            RedirectInfo redirectInfo;

            if (RedirectFromTo.TryGetValue(path, out redirectInfo) && !string.IsNullOrWhiteSpace(redirectInfo.To))
            {
                contentRequest.SetRedirect(redirectInfo.To, redirectInfo.StatusCode);
                redirect = true;
            }

            return redirect;
        }
Exemple #4
0
        /// <summary>
        /// Follows external redirection through <c>umbracoRedirect</c> document property.
        /// </summary>
        /// <remarks>As per legacy, if the redirect does not work, we just ignore it.</remarks>
        private void FollowExternalRedirect()
        {
            if (!_pcr.HasPublishedContent)
            {
                return;
            }

            var redirectId  = _pcr.PublishedContent.GetPropertyValue(Constants.Conventions.Content.Redirect, -1);
            var redirectUrl = "#";

            if (redirectId > 0)
            {
                redirectUrl = _routingContext.UrlProvider.GetUrl(redirectId);
            }
            if (redirectUrl != "#")
            {
                _pcr.SetRedirect(redirectUrl);
            }
        }
		public bool TryFindContent(PublishedContentRequest contentRequest)
		{
			var stores = StoreHelper.GetAllStores();

			if (!stores.Any())
			{
				return false;
			}

			var uwebshopRequest = UwebshopRequest.Current;
			var content = uwebshopRequest.Product ?? uwebshopRequest.Category ?? uwebshopRequest.PaymentProvider ?? // in case ResolveUwebshopEntityUrl was already called from the module
						  IO.Container.Resolve<IUrlRewritingService>().ResolveUwebshopEntityUrl().Entity;

			if (content is PaymentProvider)
			{
				var paymentProvider = content as PaymentProvider;

				Log.Instance.LogDebug("UmbracoDefaultAfterRequestInit paymentProvider: " + paymentProvider.Name);

				new PaymentRequestHandler().HandleuWebshopPaymentRequest(paymentProvider);

				var publishedContent = contentRequest.RoutingContext.UmbracoContext.ContentCache.GetById(paymentProvider.Id);
				if (publishedContent == null) return false;
				contentRequest.PublishedContent = publishedContent;

				SetRequestCulture(contentRequest);
				return true;
			}

			if (content is Category)
			{
				var categoryFromUrl = content as Category;

				if (categoryFromUrl.Disabled) return false;

				if (Access.HasAccess(categoryFromUrl.Id, categoryFromUrl.Path, Membership.GetUser()))
				{
					var doc = contentRequest.RoutingContext.UmbracoContext.ContentCache.GetById(content.Id);
					if (doc != null)
					{
						contentRequest.PublishedContent = doc;
						var altTemplate = HttpContext.Current.Request["altTemplate"];
						contentRequest.TrySetTemplate(altTemplate);

						SetRequestCulture(contentRequest);
						return true;
					}
				}
				else
				{
					if (HttpContext.Current.User.Identity.IsAuthenticated)
					{
						contentRequest.SetRedirect(library.NiceUrl(Access.GetErrorPage(categoryFromUrl.Path)));
					}
					contentRequest.SetRedirect(library.NiceUrl(Access.GetLoginPage(categoryFromUrl.Path)));
					return true;
				}
			}

			else if (content is Product)
			{
				var productFromUrl = content as Product;
				if (productFromUrl.Disabled) return false;

				if (Access.HasAccess(productFromUrl.Id, productFromUrl.Path, Membership.GetUser()))
				{
					var doc = contentRequest.RoutingContext.UmbracoContext.ContentCache.GetById(content.Id);
					if (doc != null)
					{
						contentRequest.PublishedContent = doc;
						var altTemplate = HttpContext.Current.Request["altTemplate"];
						contentRequest.TrySetTemplate(altTemplate);

						SetRequestCulture(contentRequest);
						return true;
					}
				}
				else
				{
					if (HttpContext.Current.User.Identity.IsAuthenticated)
					{
						contentRequest.SetRedirect(library.NiceUrl(Access.GetErrorPage(productFromUrl.Path)));
					}
					contentRequest.SetRedirect(library.NiceUrl(Access.GetLoginPage(productFromUrl.Path)));
					return true;
				}
			}
			return false;
		}