Issue #13 resolved

URL-resolving functions misbehaving on Mono (for Apache use)

Ramon Snir
created an issue

I've tried running WebSharper on Apache with mod_mono. Most just worked out of the box, but I have encountered a problem with Sitelets' links.

My sitelet: {{{ Sitelet.Sum [ Sitelet.Content "/" Home HomePage Sitelet.Content "/About" About AboutPage ] }}} And I generate such a menu (both in HomePage and AboutPage): {{{ let ( => ) text url = A [HRef url] -< [Text text]

let Links (ctx: Context<Action>) = UL [ LI ["Home" => ctx.Link Home] LI ["About" => ctx.Link About] ] }}} But both pages have this HTML outputted (only on Apache, IIS version works just fine): {{{ <ul><li><a href="/">Home</a></li><li><a href="file:///About">About</a></li></ul }}}

Comments (9)

  1. Anton Tayanovskyy
    • assigned issue to toyvo

    Looks like System.Uri handling in Mono is inconsistent with .NET. I attempted to work around this, which made your particular program run. There might be more issues, please report if you encounter any. Thanks.

  2. perfectshuffle

    Fixed with 1 line change. See patch below:

    # HG changeset patch
    # User James Freiwirth
    # Date 1370820182 -3600
    
    Fix URL generation for Ctx.Link on MONO
    See also: https://bitbucket.org/IntelliFactory/websharper/issue/13/url-resolving-functions-misbehaving-on
    
    diff --git a/IntelliFactory.WebSharper.Sitelets/Router.fs b/IntelliFactory.WebSharper.Sitelets/Router.fs
    --- a/IntelliFactory.WebSharper.Sitelets/Router.fs
    +++ b/IntelliFactory.WebSharper.Sitelets/Router.fs
    @@ -47,7 +47,7 @@
    
         /// Creates an absolute or relative URI from a string.
         let makeUri uri =
    -        Uri(uri, UriKind.RelativeOrAbsolute)
    +        Uri(uri, UriKind.Relative)
    
         let isAbsoluteUri uri =
             (makeUri uri).IsAbsoluteUri
    
  3. Anton Tayanovskyy

    Sorry for the awful delay, I am just hitting this same issue again with Mono 3.2.3 and WebSharper 2.5 alpha. Your fix seems to work, as does the following (I know, absolute URIs may not be very likely but still)..

    let makeUri str =
      let mutable res = null
      if System.Uri.TryCreate(str, System.UriKind.Relative, &res) then res else
        System.Uri(str, System.UriKind.Absolute)
    

    The TryCreate methods may only work with latest frameworks (such as .NET 4x) but this is what we are targeting anyway for WebSharper 2.5. Will commit soon.

  4. Log in to comment