MVC Preview 2 Relative URL Resolution Bug

Last post 07-06-2008 3:22 PM by ta4ka. 5 replies.

Sort Posts:

  • MVC Preview 2 Relative URL Resolution Bug

    03-06-2008, 11:33 AM

    The following code: 

    <%
    = Html.Image("~/Content/Images/test.gif") %>

    Outputs the following incorrect URL path in the Preview 2 release of the MVC framework:

    <img  src="/AppBaseContent/Images/test.gif"  alt="test.gif"  />

    Note the missing directory separator between the /AppBase and the Content directory. If I remember correctly I believe this was a problem in the MVCToolkit code... It must have been ported over to the Preview 2 release.

    The ugly workaround is to put an extra path separator in the relative url path:

    <%= Html.Image("~//Content/Images/test.gif") %>

  • Re: MVC Preview 2 Relative URL Resolution Bug

    03-06-2008, 12:07 PM
    Answer
    • Loading...
    • tgmdbm
    • Joined on 12-17-2007, 9:08 AM
    • Posts 639
    • ASPInsiders

    lol.

    I don't believe this.

    From reflector: LinkExtensions

    internal static string ResolveUrl(HtmlHelper helper, string virtualUrl)
    {
    HttpContextBase httpContext = helper.ViewContext.HttpContext;
    string str = virtualUrl;
    if (!virtualUrl.StartsWith("~/", StringComparison.OrdinalIgnoreCase))
    {
    return str;
    }
    virtualUrl = virtualUrl.Remove(0, 2);
    string applicationPath = httpContext.Request.ApplicationPath;
    if (string.IsNullOrEmpty(applicationPath))
    {
    applicationPath = "/";
    }
    return (applicationPath + virtualUrl);

    This should obviously be if(string.IsNullOrEmpty(applicationPath) || !applicationPath.EndsWith("/"))


  • Re: MVC Preview 2 Relative URL Resolution Bug

    03-06-2008, 12:10 PM
    Answer
    • Loading...
    • JeremyS
    • Joined on 10-21-2006, 8:23 AM
    • UK
    • Posts 63
    Well, that's disappointing. I reported this back in December (http://forums.asp.net/t/1192434.aspx) Its also sad to see that ResolveUrl is now internal rather than public like it was before.
  • Re: MVC Preview 2 Relative URL Resolution Bug

    03-07-2008, 8:03 AM
    • Loading...
    • tgmdbm
    • Joined on 12-17-2007, 9:08 AM
    • Posts 639
    • ASPInsiders

    tagged 

    Filed under:
  • Re: MVC Preview 2 Relative URL Resolution Bug

    03-11-2008, 8:06 AM
    • Loading...
    • tgmdbm
    • Joined on 12-17-2007, 9:08 AM
    • Posts 639
    • ASPInsiders
    JeremyS:
    Its also sad to see that ResolveUrl is now internal rather than public
     

    I just tried porting to Preview 2 and this one has bitten me.

    After changing my references and updating the code, it's my ONLY compiler error. HtmlHelper does not contain a definition for ResolveUrl.

    I have no idea why they made it internal. When we get the source this is one of the first things i'm changing.

     

  • Re: MVC Preview 2 Relative URL Resolution Bug

    07-06-2008, 3:22 PM
    • Loading...
    • ta4ka
    • Joined on 09-08-2007, 8:14 AM
    • Posts 18

    Finally, got it to work with virtual path in asp.net mvc here is the code:

     

    I have a virtuel folder  'download/documents' and filesave puts it there. Not c:\myuploadedfiles

      public void SaveDocuments()
            {
                
                HttpPostedFile file = Request.Files["filPhoto"];
                _global_file = file;
                if (file.ContentLength > 0)
                {
                    string patNekoj = HttpContext.Request.MapPath("../download/documents");

                    string filePath = Path.Combine(patNekoj, Path.GetFileName(file.FileName));
                   
                   
                   
                    
                    file.SaveAs(filePath);
                   
                }
                RenderView("Upload");
             
            }

    ----------------------------------------
    http://www.shoutitonline.com/ - Website based on club site starter kit
    Web Orange Design Solutions
    http://www.web2orange.com
    http://www.weborange.com.mk
Page 1 of 1 (6 items)
Microsoft Communities
Page view counter