Click here to Skip to main content
11,478,902 members (74,496 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP.NET
Hello All,

My Website is hosted on appHarbor.When I access a page it is appending a port no with the referred Url like:"http://www.test.com/test.aspx?returnUrl=http://www.test.com:11111/abc/kgh.aspx".
It is appending 11111 port no.There by I coundnt go to that page .

I have got a method but unable to understand and use it:

public static string ToPublicUrl(this UrlHelper urlHelper, Uri relativeUri)
   {
       var httpContext = urlHelper.RequestContext.HttpContext;
 
       var uriBuilder = new UriBuilder
       {
           Host = httpContext.Request.Url.Host,
           Path = "/",
           Port = 80,
           Scheme = "http",
       };
 
       if (httpContext.Request.IsLocal)
       {
           uriBuilder.Port = httpContext.Request.Url.Port;
       }
 
       return new Uri(uriBuilder.Uri, relativeUri).AbsoluteUri;
   }


Can anybody help me...

Thanks
Posted 5-Jun-12 15:55pm
Comments
Henning Dieterichs at 9-Jun-12 14:48pm
   
And what is your question?
I don't understand your problem...
Maybe "Url-Encoding" is a point which could help you.

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

You need to override this function.
Here is the complete class for ToPublicURL


using System;
using System.Web;
using System.Web.Mvc;

namespace MileageStats.Web.Helpers
{
public static class UrlExtensions
{
// Occasionally, we need to generate a url that is publicly accessible.
// For example, in the case of authenticating with a third party we need to provide
// a return url for the third-party invoke.
// In some circumstances, such as hosting the app with a service provider that handles
// load balances by forwarding the request internally on different ports, the standard
// approach for generating a URL in ASP.NET may use one of the internal ports.
// ToPublicUrl helps us a create a URL that will be publically accessible.
public static string ToPublicUrl(this UrlHelper urlHelper, string action, string controller)
{
var uri = new Uri(urlHelper.Action(action, controller), UriKind.Relative);
return ToPublicUrl(urlHelper, uri);
}

public static string ToPublicUrl(this UrlHelper urlHelper, Uri relativeUri)
{
var request = urlHelper.RequestContext.HttpContext.Request;
return ToPublicUrl(request,relativeUri);
}

public static string ToPublicUrl(this HttpRequestBase request, Uri relativeUri)
{
var url = request.Url;
return ToPublicUrl(url.Host,url.Scheme,url.Port,request.IsLocal, relativeUri);
}

public static string ToPublicUrl(this HttpRequest request, Uri relativeUri)
{
var url = request.Url;
return ToPublicUrl(url.Host, url.Scheme, url.Port, request.IsLocal, relativeUri);
}

//Note: this assumeS that port 80 will always be used when not running locally.
private static string ToPublicUrl(string host, string scheme, int port, bool isLocal, Uri relativeUri)
{
var uriBuilder = new UriBuilder
{
Host = host,
Path = "/",
Port = 80,
Scheme = scheme,
};

if (isLocal)
{
uriBuilder.Port = port;
}

return new Uri(uriBuilder.Uri, relativeUri).AbsoluteUri;
}

public static string UnencodedAction(this UrlHelper helper, string action, string controller, object routeValues)
{
return HttpUtility.UrlDecode(helper.Action(action, controller, routeValues));
}
}
}


reference link
https://github.com/mspnp/mobile-web/blob/master/MileageStats.Web/Helpers/UrlExtensions.cs[^]
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 200
1 F-ES Sitecore 195
2 Frankie-C 120
3 OriginalGriff 105
4 DamithSL 95
0 Sergey Alexandrovich Kryukov 7,880
1 OriginalGriff 7,341
2 Sascha Lefèvre 3,064
3 Maciej Los 2,491
4 Richard Deeming 2,335


Advertise | Privacy | Mobile
Web01 | 2.8.150520.1 | Last Updated 9 Jan 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100