[Help] Url rewriting and Images ref

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Fransis il Mulo

    #1

    [Help] Url rewriting and Images ref

    I wrote code to manage Urlrewriting in Application_Beg inRequest:

    if (!System.IO.Fil e.Exists(Reques t.PhysicalPath) )
    {
    string sRequestedUrl = Request.Path;
    string sTargetUrl = GetRurl(sReques tedUrl);
    Context.Rewrite Path(sTargetUrl , false);
    }

    GetRurl map real url on virtual url.

    I get a problem with images ref. In the root dir i have a subdir called
    images and in html code I have ref like these:

    <img src="images/img.jpg">
    or
    <body background="ima ges/back.jpg">

    When the code transforms shop/books/one.html in content.aspx?id =123456 I
    obtain an exception due to wrong path (shop/books/images/img.jpg instead
    of images/img.jpg). If a use ref like ~/images/img.jpg I still obtain
    wrong Request.Physica lPath...

    The url of my application is http://MySite/MyApp.


    Can you help me?


    Bye

    Fransis
  • Fransis il Mulo

    #2
    Re: [Help] Url rewriting and Images ref

    I try to explain:

    In my page i've two tag like these:


    <link href="~/styles/style.css" rel="stylesheet " type="text/css" />

    and

    <body background="~/img/image.jpg" topmargin=0 bottommargin=0>

    the property Request.Physica lPath return a right value

    "c:\\inetpub\\w wwroot\\myApp\\ styles\\style.c ss" and a wrong value

    "c:\\inetpub\\w wwroot\\myApp\\ ~\\img\\image.j pg".

    Why? Can you help me?

    Comment

    • =?Utf-8?B?YnJ1Y2UgYmFya2Vy?=

      #3
      Re: [Help] Url rewriting and Images ref

      the ~path is evaluated at render time only for server controls (those with a
      runat=server). what confusing is that the <head(and any child <link>s) s a
      server control. the <bodyis not a server control automatically.

      if you us a ~path on a non-server control, its rendered as ~path, and thats
      what the browser will send.

      -- bruce (sqlwork.com)


      "Fransis il Mulo" wrote:
      I try to explain:
      >
      In my page i've two tag like these:
      >
      >
      <link href="~/styles/style.css" rel="stylesheet " type="text/css" />
      >
      and
      >
      <body background="~/img/image.jpg" topmargin=0 bottommargin=0>
      >
      the property Request.Physica lPath return a right value
      >
      "c:\\inetpub\\w wwroot\\myApp\\ styles\\style.c ss" and a wrong value
      >
      "c:\\inetpub\\w wwroot\\myApp\\ ~\\img\\image.j pg".
      >
      Why? Can you help me?
      >

      Comment

      • =?Utf-8?B?YnJ1Y2UgYmFya2Vy?=

        #4
        RE: [Help] Url rewriting and Images ref

        you need to set the path relative to what the browser sees. as you are using
        url rewriting you are tricking .net

        take url



        which is rewritten



        now if you use ~/images/image.gif, .net determines the current request is at
        the base dir so it renders:

        src="images/image.gif"

        but the browser sees the before url. so when it requests the image it sends:



        because to it the base dir is "http://mysite/myapp/mypage"

        you need to url the image requests also, calc the path in your code.

        -- bruce (sqlwork.com)


        "Fransis il Mulo" wrote:
        I wrote code to manage Urlrewriting in Application_Beg inRequest:
        >
        if (!System.IO.Fil e.Exists(Reques t.PhysicalPath) )
        {
        string sRequestedUrl = Request.Path;
        string sTargetUrl = GetRurl(sReques tedUrl);
        Context.Rewrite Path(sTargetUrl , false);
        }
        >
        GetRurl map real url on virtual url.
        >
        I get a problem with images ref. In the root dir i have a subdir called
        images and in html code I have ref like these:
        >
        <img src="images/img.jpg">
        or
        <body background="ima ges/back.jpg">
        >
        When the code transforms shop/books/one.html in content.aspx?id =123456 I
        obtain an exception due to wrong path (shop/books/images/img.jpg instead
        of images/img.jpg). If a use ref like ~/images/img.jpg I still obtain
        wrong Request.Physica lPath...
        >
        The url of my application is http://MySite/MyApp.
        >
        >
        Can you help me?
        >
        >
        Bye
        >
        Fransis
        >

        Comment

        Working...