Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5992379
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T23:31:23+00:00 2026-05-22T23:31:23+00:00

[Apologies if my question title does not accurately describe my problem- if you can

  • 0

[Apologies if my question title does not accurately describe my problem- if you can think of a better title and have the permissions to change this then please feel free to change it!].

I think that I have stumbled upon a minor breaking change between ASP.Net 3.5 and 4.0.

[Edit: I have confirmed that there is a change in behaviour twix 3.5 and 4.0 – see my answer]

Here is the scenario: –

I have a ASP.Net 3.5 web application.
I have a trivial user control {appRoot}/Controls/Widgets/MyPictureAndTextWidget.ascx that essentially contains some text and another user control ({appRoot}/Controls/Widgets/MyPicture.ascx).

For the most part, this control is used in the normal fashion – i.e. including it in the mark up of other pages but I have one instance where I need to obtain the HTML to render on the client using Ajax.

The way I achieved this was to write an asmx web service that programmatically created a new Page and dynamically `LoadControl’ the user controls and then captured the output from the rendering of the page in a string builder – particulary inelegant but it worked! See bottom for the source.

However, after upgrading the project to Asp.Net 4.0, the above code no longer works as it used to; the image, when rendered has src="../images/xxx.png (note the ‘../’ which is not wanted).

I have created a little demo app http://cid-916198839f3e806c.office.live.com/self.aspx/Public/TestingImageWTF.zip if you want to run it for yourselves. When you compile the app using 3.5, it works (i.e. you see 2 pictures of a spider on the test page) but when you compile and run under 4.0, you only see 1 spider (the other image has the wrong URL).

The only explanation that I can come up with is that the ResolveClientUrl method (which the Image control will use in order to work out what is the relative path to the image from the currently executing page) is behaving differently. The fact that the image url is coming out as “../images/xxx.png” means that the Image control ‘thinks’ it is executing in a page that has a path like ‘{appRoot}/folder/handler’ when running under 4.0 but it thinks it is running in a context ‘{appRoot}/handler’ under 3.5.

I hope this is making sense to you – sorry if I am not describing the problem very clearly or concisely.

Can anyone either tell us how: –

  • to restore the 3.5 behaviour (without reverting to the 3.5 framework obviously!)

  • or a better way of generating the HTML in the web service in the first place?

The source

A full test application can be downloaded from here http://cid-916198839f3e806c.office.live.com/self.aspx/Public/TestingImageWTF.zip

Web Service

    [WebMethod]
    [ScriptMethod]
    public string GetWidgetHtml(int number)
    {
        var pageHolder = new Page
                             {
                                         //AppRelativeVirtualPath = "~/" // I tried playing with this but it made no difference!
                             };
        for (int i = 0; i < number; i++)
        {
            var viewControl = (MyPictureAndTextWidget) pageHolder.LoadControl(@"~/Controls/Widgets/MyPictureAndTextWidget.ascx");
            pageHolder.Controls.Add(viewControl);
        }

        var output = new StringWriter();

        HttpContext.Current.Server.Execute(pageHolder, output, false);

        StringBuilder sb = output.GetStringBuilder();
        string fulloutput = sb.ToString();
        return fulloutput;
    }

Here are the contents of my user controls

Controls/Widgets/MyPictureAndTextWidget.ascx

    <%@ Control Language="C#" AutoEventWireup="true" CodeBehind="MyPictureAndTextWidget.ascx.cs" Inherits="TestingImageWTF.Controls.Widgets.MyPictureAndTextWidget" %>
    <%@ Register TagName="Picture" TagPrefix="widget" Src="~/Controls/Widgets/MyPictureWidget.ascx" %>

    <div style="background:#EEEEEE; border:1px dashed;">
        <h4>My control</h4>
        Some text from the widget ....: 
        <br /><widget:Picture runat="server" />
    </div>

Controls/Widgets/MyPictureWidget.ascx

    <%@ Control Language="C#" AutoEventWireup="true" CodeBehind="MyPictureWidget.ascx.cs" Inherits="TestingImageWTF.Controls.Widgets.MyWidget" %>

    <script runat="server">
        protected void Page_Load(object sender, EventArgs e)
        {
            image.ImageUrl = "~/images/spider.png";
        }
    </script>
    <asp:Image ID="image" runat="server" />
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T23:31:24+00:00Added an answer on May 22, 2026 at 11:31 pm

    oSo here is at least part if the answer.

    Question: Does ResolveClientUrl working differently in ASP.Net 4 and 3.5?

    Answer: Yes.

    And the change in behaviour (that I know of) is that it treats PathInfo differently.

    To demonstrate, make the following page.

    <%@ Page Language="C#" AutoEventWireup="true"  %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <body>
        <form id="form1" runat="server">
            DateTime.Now.Ticks: <%= DateTime.Now.Ticks %>
            <br />
            <asp:HyperLink runat="server" NavigateUrl="~/PathInfoLinkTest.aspx">This links to ~/PathInfoLinkTest.aspx</asp:HyperLink>
            <br />
            <asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl="~/PathInfoLinkTest.aspx/foo/bar">This links to ~/PathInfoLinkTest.aspx/foo/bar</asp:HyperLink>
            <br />
            ResolveClientUrl("~/PathInfoLinkTest.aspx/foo/bar") = <%= ResolveClientUrl("~/PathInfoLinkTest.aspx/foo/bar") %>
        </form>
    </body>
    </html>
    

    And run under .Net4 and .Net 3.5.

    You will see that under 3.5:
    ResolveClientUrl(“~/PathInfoLinkTest.aspx/foo/bar”) = ‘PathInfoLinkTest.aspx/foo/bar‘

    whereas under 4.0 you get
    ResolveClientUrl(“~/PathInfoLinkTest.aspx/foo/bar”) = ‘bar‘

    The change seems to be a bug fix in response to the problems that these folk were having.

    • http://channel9.msdn.com/Forums/TechOff/256519-Am-I-crazy-here-but-there-appears-to-be-an-oversight-in-ASPNET

    • http://forums.asp.net/t/1138135.aspx/1

    In essence, the bug in 3.5 is that if you are currently browsing the url http://host/app/page.aspx/foo/bar and you want to link to http://host/app/page2.aspx, then the URL as rendered on the client should be ../../page2.aspx.

    Asp.Net 4 gets this correct!
    Asp.Net 3.5 doesn’t – it outputs the link’s url as ‘page2.aspx‘ (so when clicked, the browser will request the page ‘http://host/app/page.aspx/foo/bar/page2.aspx‘. You can see a manifestation of this bug if you run the above page in .Net 3.5 and click on the 2nd hyperlink several times – then have a look in your browser’s address bar!

    Unfortunately the bug fix broke my code – because my code was relying on the (incorrect) behaviour of .Net 3.5: The web service request always has Pathinfo (the web service method name) and so when the controls render themselves, calls to ResolveClientUrl(“~/xxx”) (correctly) puts returns “../xxx”.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Apologies for the poor question title - I'm not sure how to describe what
Firstly, apologies for the bad question title - not entirely sure if I am
Apologies for probably simple question, I've read the docs and still can't get this
Apologies in advance for the length of this question! I have a data structure
Apologies in advance for the long-winded question. I'm really a database programmer, but have
Final question for the night. And apologies for the complete noobness of this. I
I am just checking out F#, so apologies if this is a silly question,
First of all, apologies for the subjective sounding title. This is intended as a
I apologize for the newbie question, but I am struggling with this problem. I
First off, I'm not entirely sure that my question title is very descriptive, so

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.