Asp.net mvc 获取MVC应用程序中文件的绝对url

Asp.net mvc 获取MVC应用程序中文件的绝对url,asp.net-mvc,Asp.net Mvc,我在Asp.Net MVC 5网站上有以下内容: @Url.Content("~/shareimage.jpg") 这给了我一个相对的url。但是我需要绝对url <%= Url.Action("About", "Home", null, "http") %><br /> <%= Url.RouteUrl("Default", new { Action = "About" }, "http") %><br /> 如何获取文件的绝对url 谢谢,

我在Asp.Net MVC 5网站上有以下内容:

@Url.Content("~/shareimage.jpg")
这给了我一个相对的url。但是我需要绝对url

<%= Url.Action("About", "Home", null, "http") %><br />
<%= Url.RouteUrl("Default", new { Action = "About" }, "http") %><br />
如何获取文件的绝对url

谢谢,,
Miguel

Url.Action或Url.RouteUrl,其中指定了协议,为您提供绝对Url

<%= Url.Action("About", "Home", null, "http") %><br />
<%= Url.RouteUrl("Default", new { Action = "About" }, "http") %><br />



Url.Action或Url.RouteUrl,其中指定了协议,为您提供绝对Url

<%= Url.Action("About", "Home", null, "http") %><br />
<%= Url.RouteUrl("Default", new { Action = "About" }, "http") %><br />



这是这个问题的副本:

我自己使用这个助手:

public static class Helpers
{
  public static Uri FullyQualifiedUri( this HtmlHelper html , string relativeOrAbsolutePath )
  {
    Uri        baseUri  = HttpContext.Current.Request.Url ;
    string     path     = UrlHelper.GenerateContentUrl( relativeOrAbsolutePath, new HttpContextWrapper( HttpContext.Current ) ) ;
    Uri        instance = null ;
    bool       ok       = Uri.TryCreate( baseUri , path , out instance ) ;
    return instance ; // instance will be null if the uri could not be created
  }
}

这将为您提供一个完全限定的绝对URI,用于您抛出的几乎所有URI。

这是这个问题的重复:

我自己使用这个助手:

public static class Helpers
{
  public static Uri FullyQualifiedUri( this HtmlHelper html , string relativeOrAbsolutePath )
  {
    Uri        baseUri  = HttpContext.Current.Request.Url ;
    string     path     = UrlHelper.GenerateContentUrl( relativeOrAbsolutePath, new HttpContextWrapper( HttpContext.Current ) ) ;
    Uri        instance = null ;
    bool       ok       = Uri.TryCreate( baseUri , path , out instance ) ;
    return instance ; // instance will be null if the uri could not be created
  }
}

这将为您提供一个完全限定的绝对URI,它几乎适用于您抛出的任何URI。

我认为,这是针对ASP.NET表单的,而不是针对MVCPlease的,请阅读我的问题。。。我正在使用Url.Content,但这给了我相对路径。是的,我知道Action和RouteUrl有一个协议选项,但这是针对Action的,而不是针对文件的。。。和Url.Content没有它。。。这就是问题所在,我认为,是ASP.NET表单而不是MVCPlese,请阅读我的问题。。。我正在使用Url.Content,但这给了我相对路径。是的,我知道Action和RouteUrl有一个协议选项,但这是针对Action的,而不是针对文件的。。。和Url.Content没有它。。。这就是可能重复的问题