Get the web service address for use in response properties

I have a response which holds a list of self-referring URLs. So I call something like /party/1 and it will return a response with a string property for `ImageUrl’. The image URL is just a specific call back to another web service on the same host.

What is the best way to create this self-referncing URL? The best I could come up with is:

        public static string GetPartyImageUrl(string party, IRequest request)
        {
            // build http request
            string partyName = party.ToLower().Replace(" ", "_").Replace(".", "");
            var imageRequest = new PartyImage() { PartyAbbreviation = partyName }.ToGetUrl();
            var url = (request.IsSecureConnection ? "https" : "http") + "://" + ((HttpRequestWrapper)request.OriginalRequest).Url.Authority + imageRequest;
            return url;
        }

Example:

Maybe you’re looking for base.Request.ResolveAbsoluteUrl()? e.g.

var relativeUrl = new PartyImage { PartyAbbreviation = partyName }.ToGetUrl();
var url = base.Request.ResolveAbsoluteUrl("~/".CombineWith(relativeUrl));
return HttpResult.Redirect(url);

Hi @mythz

Your suggestion does not work as expected though.

Value of url in the code above is: /json/reply/String?length=46

This definitely does not look correct to me. I am not looking to redirect however. I want to return a string to be set in a response object.

public class TestResponse 
{
    public string PartyLogoUrl { get;set; }
}

The PartyLogo URL would refer back to one of my own ServiceStack services.

Actually my bad was typing free-hand, I missed the .ToGetUrl() off the Request DTO (was on string instead), I’ve rewritten it so it’s clearer:

var relativeUrl = new PartyImage { PartyAbbreviation = partyName }.ToGetUrl();
var url = base.Request.ResolveAbsoluteUrl("~/".CombineWith(relativeUrl));
return HttpResult.Redirect(url);