views:

92

answers:

4

Hello,

I am using WebRequest to retreive a html page from the web and then displaying it using Response.Write.

The resulting page looks different from the original mostly in font and layout.

What could be the possible reasons and how to fix it?

With thanks,

Wineshtain.

+1  A: 

The reason might be that the original html page contains relative (to the original site) paths to the stylesheet files so when you render the html in your site it cannot find the css.

Darin Dimitrov
+1  A: 

Does the remote web site include CSS, JavaScript, or images?

If so, are any of the above resources referenced with relative links (i.e.: /javascript/script.js)?

If so, when the browser receives the HTML from your server, the relative links (which were originally relative to the source server) are now relative to your server.

You can fix this by either changing the HTML to use absolute links (i.e.: http://www.server.com/javascript/script.js). This is more complicated than it sounds: you'll need to catch <link href="..."/>, <a href="..."/>, <form action="..."/>, <script src="..."/>, <img src="..."/>, etc.

A more limited solution would be to place the actual resources onto your server in the same structure as they exist on the original server.

Chris Nielsen
+1  A: 

Most probably, the HTML you retrieve contains relative URLs for loading images, stylesheets, scripts. These URLs are not correct for the page as you serve it from your site. You can fix this by converting all of the relative URLs into absolute URLs or by including a BASE tag in the head of the HTML, pointing to the URL of the original page.

Be advised though that deeplinking to images and other resources is considered bad practice. The source site may not like what you are doing.

Teun D
+1  A: 

The remote site might look at the User-Agent and serve different content based on that.

Also, you should compare the HTML you can retrieve from the remote site, with the HTML you get by visiting the site in a browser. If they are not different, you are probably missing images and/or css and javascript, because of relative paths, as already suggested in another answer.

driis