Ticket #24 (closed enhancement: fixed)

Opened 4 months ago

Last modified 4 months ago

Application-related uris

Reported by: Artem Tikhomirov Assigned to:
Priority: major Component:
Keywords: Cc:

Description

It'll be nice if you'd added application-related uri resolving in href and src attributes.


That's a good idea. Probably something like {{{<img src="~/content/images/etc.png"/>}}}?

In MonoRail that could also be "${SiteRoot}/content/images/etc.png" but I don't know what a similar property in asp.net mvc would be.

Is there a set of known element-attributes that should be treated as relative url? -Lou

Change History

07/28/08 16:49:13 changed by marius

Not sure about asp.net mvc, but in asp.net (as under mvc we still have asp.net engine) for site root we might use HttpRequest.ApplicationPath (additional transformations might be needed)

07/28/08 16:50:48 changed by anonymous

Maybe a ${SiteRoot} could be used in both Monorail and asp.net mvc. Then a set of attributes is not needed to be known in advance.

07/29/08 05:41:51 changed by louis.dejardin

  • status changed from new to closed.
  • resolution set to fixed.

Added a node visitor which looks for "~/" at the start of a number of known attributes. It's essentially changed to "${SiteRoot?}/" which is a property that's now available to mr and asp.net mvc.

The asp.net mvc siteroot is normalized as follows

private string _siteRoot;
public string SiteRoot
{
    get
    {
        if (_siteRoot == null)
        {
            var appPath = ViewContext.HttpContext.Request.ApplicationPath;
            if (string.IsNullOrEmpty(appPath) || string.Equals(appPath, "/"))
            {
                _siteRoot = string.Empty;
            }
            else
            {
                _siteRoot = "/" + appPath.Trim('/');
            }
        }
        return _siteRoot;
    }
}

The following attributes are examined. These are the attributes that were of type URI in the html spec.

_specs = new[] 
{
    new ElementSpecs("a","href"),
    new ElementSpecs("applet", "codebase"),
    new ElementSpecs("area", "href"),
    new ElementSpecs("base", "href"),
    new ElementSpecs("blockquote", "cite"),
    new ElementSpecs("body", "background"),
    new ElementSpecs("del","cite"),
    new ElementSpecs("form", "action"),
    new ElementSpecs("frame", "longdesc", "src"),
    new ElementSpecs("head", "profile"),
    new ElementSpecs("iframe", "longdesc", "src"),
    new ElementSpecs("img", "longdesc", "src", "usemap"),
    new ElementSpecs("input", "src", "usemap"),
    new ElementSpecs("ins", "cite"),
    new ElementSpecs("link","href"),
    new ElementSpecs("object", "classid", "codebase", "data", "usemap"),
    new ElementSpecs("script", "src"),
    new ElementSpecs("q", "cite") 
};