Hi
A user received this error when trying to view a page he just created:
PathTooLongException: The specified path, file name, or both are too long. The fully qualified file name must be less than 260 characters, and the directory name must be less than 248 characters.
The node name was very long.
I suggested they set a shorter urlName, but is there some way to validate that either the node name is less than 260 OR the UrlName is less than 260 characters?
I guess I can set up a publish event handler to deal with it and cancel publish.
Should this be something that umbraco does out of the box?
Hi
I am using umbraco 7.2.1 and I got the issue again, can anyone help me with the implementation of the method above? I keep getting messages for using deprecated methods and classes
this is the code:
public class UrlValidation : ApplicationEventHandler
{
public void UrlValidationEvent()
{
Document.BeforePublish += ValidateUrlSegmentLength;
}
private void ValidateUrlSegmentLength(Document sender, PublishEventArgs e)
{
var urlName = DocumentExtensions.GetPropertyAsString(sender, "umbracoUrlName");
if (urlName.HasValue() == false && sender.Text.Length > 200)
{
e.Cancel = true;
var page = HttpContext.Current.Handler as Page;
if (page != null)
{
page.PreRenderComplete += (s, a) => umbraco.BasePages.BasePage.Current.ClientTools.ShowSpeechBubble(
umbraco.BasePages.BasePage.speechBubbleIcon.error,
"Not Published", "Please add a shorter UrlName"
);
}
}
}
}
Validating for URL path segment length
Hi
A user received this error when trying to view a page he just created:
The node name was very long.
I suggested they set a shorter urlName, but is there some way to validate that either the node name is less than 260 OR the UrlName is less than 260 characters?
I guess I can set up a publish event handler to deal with it and cancel publish.
Should this be something that umbraco does out of the box?
ok, here's what I did
Document.BeforePublish += ValidateUrlSegmentLength;
I also added a regex validation to umbracoUrlName
.{0,200}
I think this should be validated out of the box. There is already a issue for this in the issue tracker : http://issues.umbraco.org/issue/U4-1955
You can vote this up.
Voted.
Hi Can you explain how to implement this solution? do I need to inherit from "ApplicationEventHandler"? Thanks I am using umbraco version 7.1.4
Yes, see http://our.umbraco.org/documentation/Reference/Events/application-startup
Thanks I am using ver 7.1.8 and I think the problem is solved in this version. I tried really long urls an didn't get any YSOD :)
Hi I am using umbraco 7.2.1 and I got the issue again, can anyone help me with the implementation of the method above? I keep getting messages for using deprecated methods and classes this is the code:
is working on a reply...