Click here to Skip to main content
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 14: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 403
1 OriginalGriff 354
2 George Jonsson 202
3 Shemeemsha RA 148
4 Animesh Datta 130
0 OriginalGriff 6,189
1 Sergey Alexandrovich Kryukov 5,666
2 CPallini 4,810
3 George Jonsson 3,429
4 Gihan Liyanage 2,522


Advertise | Privacy | Mobile
Web04 | 2.8.140916.1 | Last Updated 9 Jan 2013
Copyright © CodeProject, 1999-2014
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