U4-288 - Url for Scheduled Items throws an error when specified as relative path

Created by Sebastiaan Janssen 19 Aug 2012, 14:50:59 Updated by Sebastiaan Janssen 01 Mar 2018, 18:47:45

Tags: PR

When you specifiy a relative path /handlers/testhandler for a scheduled item an exception is thrown that the path is a invalid uri. So we have to specify the absolute path http:///mygreatumbracosite.comhandlers/testhandler This is okay if you configure the umbracosettings by hand, but if you use a Package Action it would be much easier if we could use a relative path..

''Originally created on CodePlex by [rsoeteman|http://www.codeplex.com/site/users/view/rsoeteman]'' on 5/27/2009 10:19:06 AM [Codeplex ID: 22757 - Codeplex Votes: 15]

Imported comments

''Comment by [Myster|http://www.codeplex.com/site/users/view/Myster] on 9/4/2011 11:00:43 PM:'' This also creates a pitfall that could be avoided when deploying a site from test -> live. NB: Using 'localhost' is not suitable. I suggest both absolute and relative paths should work.

''Comment by [Diplo|http://www.codeplex.com/site/users/view/Diplo] on 6/19/2012 9:49:27 AM:'' I also agree this adds an overhead when deploying sites from a development to staging to live environment (and vice versa). It's every easy to overlook. A relative URL would be the prefect fix and would (surely) be simple to implement? Yet here we are 3 years later and still not done?

''Comment by [hartvig|http://www.codeplex.com/site/users/view/hartvig] on 7/12/2012 4:10:18 PM:'' The big issue is that we can't know about the current url as the schedule tasks runs in a separate thread (not knowing anything about what url the site is running on). Ie. when the timer that executes the scheduled tasks runs, it doesn't have a browser request to know about a url, it's just called from the "IIS application" itself.

One solution could be to look if any domain is assigned to the Umbraco solution (using the APIs from the assign hostnames right click menu functionality), but it does smell a bit of a hack (and would probably not solve the live/dev scenario).

Any ideas for possible solutions are more than welcome.

''Comment by [BertrandLeRoy|http://www.codeplex.com/site/users/view/BertrandLeRoy] on 7/13/2012 10:32:15 AM:'' FWIW, in Orchard we have a setting for the root URL of the site. Not the greatest solution, but it helps for those cases where you can't reliably determine it from the environment. We also try to handle ~/ URLs everywhere we can. In some contexts, it allows you to reject absolute URLs altogether as invalid. Not sure I understand all the constraints in the context of Umbraco but I thought I'd mention it just in case.

''Comment by [tocsoft|http://www.codeplex.com/site/users/view/tocsoft] on 7/13/2012 10:40:40 AM:'' Niels drop this code into UmbracoContext it should let you then call UmbracoContext.ToAbsoluteUrl("~/virtualPathHere") and it its a virtual path then it will then resolve it will also ignore none virtual ones.

this is soo untested but should give you a starting point.

Scott.

private static string _lastBaseUrl;

public static string ToAbsoluteUrl(string virtualPath) { var idx = virtualPath.IndexOf("/"); if (string.IsNullOrWhiteSpace(_lastBaseUrl) && idx == 0) { throw new Exception("Can only be used after the first request that uses UmbracoContext"); } if (virtualPath.IndexOf("/") == 0) { // prevents a double forward slash if (_lastBaseUrl[0] == '/') return _lastBaseUrl + virtualPath.Substring(2); else return _lastBaseUrl + virtualPath.Substring(1); }

return virtualPath; }

public UmbracoContext(HttpContext httpContext) { m_HttpContext = httpContext; _lastBaseUrl = m_HttpContext.Request.Url.GetLeftPart(UriPartial.Authority) + VirtualPathUtility.ToAbsolute("~/"); }

''Comment by [hartvig|http://www.codeplex.com/site/users/view/hartvig] on 7/13/2012 11:21:33 AM:'' @tocsoft: Great and simple idea. If the app is actually warn, some url have been sent so that makes sense.

@BertrandLeRoy: Thank for the feedback, but unfortunately this wouldn't be different from what we already have (ie. that you'd have to swap the url between your environments (with different urls for dev/stage/prod).

''Comment by [tocsoft|http://www.codeplex.com/site/users/view/tocsoft] on 7/13/2012 11:27:18 AM:'' woops code snippet is wrong

if (_lastBaseUrl[0] == '/')

should read

if (_lastBaseUrl[_lastBaseUrl.Length -1] == '/')

checking last char not first

''Comment by [tocsoft|http://www.codeplex.com/site/users/view/tocsoft] on 7/15/2012 3:09:05 PM:'' pull request with a fix for this.

http://umbraco.codeplex.com/SourceControl/network/forks/tocsoft/relativeSchedule/contribution/3102

Comments

Scott Williams 22 Aug 2012, 08:26:51

that last pull request got rejected for good reason, but i've got the time today to do another one, will submit one later today.


Scott Williams 22 Aug 2012, 09:25:35

my branch is at http://umbraco.codeplex.com/SourceControl/network/forks/tocsoft/AppRelaticeSchedule


Scott Williams 22 Aug 2012, 10:10:13

pull request for this issue http://umbraco.codeplex.com/SourceControl/network/forks/tocsoft/AppRelaticeSchedule/contribution/3282


Scott Williams 03 Sep 2012, 14:48:01

Just wondering if is this likely to be pulled in for 4.9?

There are no backwards compatibility issues and I've even provided some unit tests for the parts that I could figure out how to test?

This issue/feature request was voted quite high on Codeplex and has been around for years it would be a shame to miss the 4.9 release.


Sebastiaan Janssen 03 Sep 2012, 14:53:36

Hey Scott, I have been unable to do a proper review for this one at the moment, sorry. Luckily, 4.10 is only a month away!


Scott Williams 03 Sep 2012, 15:00:24

no problem, just making sure it hadn't been been forgotten.


Heather L Floyd 29 Oct 2015, 00:27:44

@sebastiaan - Will this fix ever get added to the core? or should we all stop hoping for it? Thanks!


Sebastiaan Janssen 30 Oct 2015, 09:56:56

Whoa, blast from the past! Well, haven't looked at this for 3 years it seems but we'd be very happy to look at a new pull request for this. :)


Morten Bock 01 Mar 2018, 18:19:49

Added PR here: https://github.com/umbraco/Umbraco-CMS/pull/2489


Priority: Up for grabs

Type: Bug

State: Fixed

Assignee:

Difficulty: Normal

Category:

Backwards Compatible: True

Fix Submitted: Pull request

Affected versions: 7.2.8

Due in version: 7.9.3

Sprint:

Story Points:

Cycle: