473,385 Members | 2,210 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

[Help] Url rewriting and Images ref

I wrote code to manage Urlrewriting in Application_BeginRequest:

if (!System.IO.File.Exists(Request.PhysicalPath))
{
string sRequestedUrl = Request.Path;
string sTargetUrl = GetRurl(sRequestedUrl);
Context.RewritePath(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="images/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.PhysicalPath...

The url of my application is http://MySite/MyApp.
Can you help me?
Bye

Fransis
Feb 25 '08 #1
3 1057
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.PhysicalPath return a right value

"c:\\inetpub\\wwwroot\\myApp\\styles\\style.cs s" and a wrong value

"c:\\inetpub\\wwwroot\\myApp\\~\\img\\image.jp g".

Why? Can you help me?
Feb 25 '08 #2
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.PhysicalPath return a right value

"c:\\inetpub\\wwwroot\\myApp\\styles\\style.cs s" and a wrong value

"c:\\inetpub\\wwwroot\\myApp\\~\\img\\image.jp g".

Why? Can you help me?
Feb 25 '08 #3
you need to set the path relative to what the browser sees. as you are using
url rewriting you are tricking .net

take url

http://mysite/myapp/mypage/fake.htm

which is rewritten

http://mysite/myapp/mypage.aspx?id=fake

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:

http://mysite/myapp/mypage/images/image.gif

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_BeginRequest:

if (!System.IO.File.Exists(Request.PhysicalPath))
{
string sRequestedUrl = Request.Path;
string sTargetUrl = GetRurl(sRequestedUrl);
Context.RewritePath(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="images/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.PhysicalPath...

The url of my application is http://MySite/MyApp.
Can you help me?
Bye

Fransis
Feb 25 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Jack Smith | last post by:
Help needed on this question. Any help is appreciated. Thanks in advance. Given a binary string (i.e. a finite sequence of 0's and 1's) we choose any two digit substring 01 and replace it by a...
5
by: Craig Keightley | last post by:
Please help, i have attached my page which worksin IE but i cannnot get the drop down menu to fucntion in firefox. Any one have any ideas why? Many Thanks Craig ...
0
by: Lee | last post by:
Hi all ;) Preamble -------- I'm using URL rewriting to enforce a frames policy (yeah, I know frames are 'bad' :) - i.e. if a request comes in for a page which should be nested within a...
13
by: Ikke | last post by:
Hi everybody, I've downloaded a design from www.oswd.org and have started rewriting the css and html to end up with a new design for my site. So far so good, but there are a few problems I...
1
by: Greg Collins [Microsoft MVP] | last post by:
I have a site that uses a custom 404 error page to perform URL Rewriting. This works excellent for all my needs except for one area. When transforming XML, I have some XSLT code that uses the...
8
by: =?Utf-8?B?bXVzb3NkZXY=?= | last post by:
Hi guys I'm having trouble with URL rewriting using HttpApplication.Context.RewritePath in a web application I've created. Everything works, but the links (css, images) in the pages break when...
23
by: SaraLeePerson | last post by:
Dear group, I am seeking a easy to maintain and more importantly *working* way to pre-fetch images, so the pages I develop load smoothly without seeing the images kick in flicker as they usually...
3
by: Fransis il Mulo | last post by:
Yesterday I posted about Url-Rewriting. Now I have solved this kind of problem but now I have troubles deploying on Win2003 my application. I develop apps on VS 2005 and XP pro. To manage...
1
by: Raymon Du | last post by:
Hi, This is te first time I use url rewriting. What I am trying to accomplish: Hide the .aspx extension and give user a shorter path to type, say the user can type "/sales" in browser and the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.