开发者

ASP.net Server.Transfer problem + Images are not getting

Hii,

I can't get the images when i using the Server.Transfer to transfer the page

I have a page Page1.aspx in a folder folder1.In the folder1 there is another folder subfolder1 and inside subfolder1 one page Page2.aspx. The images are kept in a folder named images that is placed in the folder1. Initially i have transfered the page from Page1.aspx to Page2.aspx that has been successfully done. But when i tried to transfer from the Page2.aspx to Page1.aspx the images could not loaded. Is there any way to load the image 开发者_StackOverflow社区correctly by using the Server.Transfer statement


I'm not convinced that the problem is with Server.Transfer. Rather, ensure that all images (I assume you're using WebForms with Image-related controls) are loaded via ~/ path prefix:

<asp:Image ... ImageUrl="~/folder1/images/image.jpg" />


How are you requesting the images on the page?

Are you are doing it like this:

<img src="images/someimage.png" alt="" />

When you do a Server.Transfer you are telling the server to return the HTML that generated from the page you are transferring the processing to, but to leave the client URL alone.

This means that what you are doing is returning the HTML from /folder1/page1.aspx but the browser thinks it is still on /folder1/subfolder1/page2.aspx, so if your image requests are as above, the browser is looking for a folder called images under subfolder1.

You should either:

  1. Change your image requests to src="/folder1/images/someimage.png" where you're explicitly telling the browser to return to the root of the site and start from there.
  2. Not use server transfer, but instead look at using Response.Redirect or similar.
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜