Maximum length of Url property

Vote:
 

Hi,

I'm getting the following error when adding an external URL in edit mode that is longer than 255 chars:

Could not save property, and it has been reverted. Please try again.
"Src" has exceeded its limit of 255 characters.

Logfile:

2016-12-08 11:33:13,891 [25] ERROR EPiServer.Cms.Shell.UI.Rest.ContentChangeManager: Unexpected error when updating property src
EPiServer.Core.InvalidPropertyValueException: "Src" has exceeded its limit of 255 characters.
at EPiServer.Core.PropertyString.set_String(String value)
at EPiServer.SpecializedProperties.PropertyUrl.set_String(String value)
at EPiServer.Core.PropertyData.SetPropertyValue(Object value, SetPropertyValueDelegate doSet)
at EPiServer.Cms.Shell.UI.Rest.ContentChangeManager.UpdateProperties(IDictionary`2 properties, IContent content)

I wonder if it is possible to allow Url's that are longer than 255 chars?

Thanks!

#172706
Edited, Dec 08, 2016 13:05
Vote:
 

The last part of http://world.episerver.com/documentation/Items/Developers-Guide/Episerver-CMS/9/Routing/Routing/ describes how you can configure your site to allow longer urls

#172729
Dec 09, 2016 11:34
Vote:
 

I've tried adding <httpRuntime maxUrlLength="1024" relaxedUrlToFileSystemMapping="true"/> under <configuration><system.web> in Web.config without any luck. Any other ideas?

#172746
Dec 09, 2016 17:09
Vote:
 

Any progress?

AFAIK, the maxUrlLength setting is not connected to the MaxLength property of the PropertyUrl class, the 255 character maxlength is inherited from the PropertyString class.

#174017
Jan 16, 2017 17:08
Vote:
 

After further investigation, it seems the only way is to override the MaxLength property of the PropertyData implementation.

One way to do it is to create a custom backing type, like this.

[PropertyDefinitionTypePlugIn, Serializable]
	public class PropertyUrlWithLength : PropertyUrl {
		public override int MaxLength {
			get {
				var section = ConfigurationManager.GetSection("system.web/httpRuntime") as HttpRuntimeSection;
				return section?.MaxUrlLength ?? base.MaxLength;
			}
			set {
				// Cannot set from code.
			}
		}
	}

And then, on your property declare it like thus:

[Display(Order = 11), BackingType(typeof(PropertyUrlWithLength))]
public virtual Url ButtonUrl { get; set; }

My example uses Johans suggested configuration change to set the length, however, that might not be what you want.

#174018
Jan 16, 2017 17:30
Vote:
 

Hi there,

Did anyone get any solution this?

I tried all the above solutions and some more by editing web config with following settings. Also added a custom backing type and still the max length of characters I can put in the remaining Url field of Episerver Url property is 407. Need help understanding what am I missing here - 

<httpRuntime targetFramework="4.6.1" requestValidationMode="2.0" enableVersionHeader="false" maxRequestLength="51200" executionTimeout="300" maxUrlLength="10240" relaxedUrlToFileSystemMapping="true" maxQueryStringLength="2097100" />

also tried maxUrlLength - 1024/2048 & maxQueryStringLength-65536 but same output!!

also based on some other references tried below -

<requestFiltering>
<requestLimits maxUrl="30000" maxQueryString="209007151" maxAllowedContentLength="204800000" />
</requestFiltering>

nothing so far!!!

#223290
May 24, 2020 14:51
Vote:
 

I was able to solve this issue for  CMS version 11.14. Described below is the approach, I used.

  1. Create a LongURL property. 
[PropertyDefinitionTypePlugIn, Serializable]
    public class LongUrl : PropertyUrl
    {
        public override int MaxLength { get; set; } = 2048;
    }

I am overridding max length value to 2048. Default is 255.

2. Create a backing type 

        [Display(GroupName = SystemTabNames.Content, Order = 10)]
        [BackingType(typeof(LongUrl))]
        public virtual Url Url { get; set; }
#225479
Jul 17, 2020 14:15
Vote:
 

@Tanuj: That won't work for URLs above 450 characters, due to the database max length (which may or may not be an issue for you depending on your actual URL requirements).

Proposed a solution here: https://world.episerver.com/forum/developer-forum/Developer-to-developer/Thread-Container/2020/5/how-to-increase-remaining-url-length-of-episerver-url-link-type-/

#225485
Edited, Jul 17, 2020 16:24
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.