Greg,

Instead of using the AbsolutUri and changing it look at the
HttpContext.Requst.Url.Host and add the Url.Action.
However I'd strongly recommend you look at
HttpContext.Request.Headers["host"] and take the part before the ":" just
in case your side responds to various host names.
Eg.. subdomain1.site.com and subdomain2.site.com

I'm sure you can push that into a nice extension method like Tony's one.

Regards,
Corneliu.


On Fri, Apr 12, 2013 at 9:26 PM, Tony McGee <[email protected]> wrote:

>  A problem with using string replace is that if your absolute path is "/"
> (site root /Home/Index), the URI gets mangled,
> i.e.  http:www.example.com/SomeController/SomeAction
>
> I'd be tempted to create an extension method on UrlHelper to hide some of
> the ugliness:
>
>     public static class UrlHelperExtensions
>     {
>         public static string AbsoluteAction(this UrlHelper helper, string
> actionName, string controllerName)
>         {
>             string absUri =
> helper.RequestContext.HttpContext.Request.Url.AbsoluteUri;
>             string urlPath =
> helper.RequestContext.HttpContext.Request.Url.PathAndQuery;
>             return absUri.Substring(0, absUri.Length - urlPath.Length) +
> helper.Action(actionName, controllerName);
>         }
>     }
>
> then in your controller:
>
>     string returnURI = Url.AbsoluteAction("SomeAction","SomeController");
>
>
>
> On 12/04/2013 18:51, Greg Low (GregLow.com) wrote:
>
>  Hi Nathan/Dave, ****
>
> ** **
>
> This seems to work but seems ugly:****
>
> ** **
>
> string returnURI =
> HttpContext.Request.Url.AbsoluteUri.Replace(HttpContext.Request.Url.AbsolutePath,
> "") ****
>
>                         + Url.Action("SomeAction", "SomeController");****
>
> ** **
>
> I need to generate it based on where the site is deployed but it needs to
> be a full URL as it’s passed to a callback function on another site.****
>
> ** **
>
> Regards,****
>
> ** **
>
> Greg****
>
> ** **
>
> Dr Greg Low****
>
> ** **
>
> 1300SQLSQL (1300 775 775) office | +61 419201410 mobile│ +61 3 8676 4913fax
> ****
>
> SQL Down Under | Web: www.sqldownunder.com****
>
> ** **
>
> *From:* [email protected] [
> mailto:[email protected] <[email protected]>] *On
> Behalf Of *Dave Walker
> *Sent:* Friday, 12 April 2013 5:43 PM
> *To:* ozDotNet
> *Subject:* Re: MVC4 URLs****
>
> ** **
>
> We use a helper extension method to wrap as have configurable cdn esp. for
> images and other static resources. Was the only way we found we could do
> it. Extra complexity for us is we wrap a SquishIt bundle up as well to turn
> on/off minification and combination of files.****
>
>
> On 12 Apr 2013, at 08:32, Nathan Schultz <[email protected]> wrote:****
>
>  Instead of using Url.Action, couldn't you just write your own <a href>?**
> **
>
> ** **
>
> On 12 April 2013 11:17, Greg Low (GregLow.com) <[email protected]> wrote:**
> **
>
>  Hi Folks,****
>
>  ****
>
> In MVC4, in the code for a controller, what’s the best way to calculate
> the fully qualified URL for a particular action?****
>
>  ****
>
> Eg: If I use ****
>
>  ****
>
> Url.Action(“SomeAction”,”SomeController”)****
>
>  ****
>
> The intellisense for Action says “gets a fully qualified URL”. However
> what I get back is:****
>
>  ****
>
> /SomeController/SomeAction****
>
>  ****
>
> What I want is:****
>
>  ****
>
> http://www.whateversiteIhit.com/SomeController/SomeAction<http://www.somesite.com/SomeController/SomeAction>
> ****
>
>  ****
>
> As I need to pass it to an external callback.****
>
>  ****
>
> What’s the best way to do that?****
>
>  ****
>
> Regards,****
>
>  ****
>
> Greg****
>
>  ****
>
> Dr Greg Low****
>
> CEO and Principal Mentor****
>
> *SQL Down Under*****
>
> SQL Server MVP and Microsoft Regional Director****
>
> 1300SQLSQL (1300 775 775) office | +61 419201410 mobile│ +61 3 8676 
> 4913<%2B61%203%208676%204913>fax
> ****
>
> Web: www.sqldownunder.com****
>
> * *****
>
>  ****
>
>  ** **
>
>
>

Reply via email to