title: How to use Url.Content("~/asdf") inside automapper projection
body: <p>I am trying to use the UrlHelper's Content method inside an automapper projection, but it fails after the first request.  </p>
  
  <p>My map creation code looks like the following:</p>
  
  <pre><code>protected override void Initialize(RequestContext requestContext) {
    base.Initialize(requestContext);
  
    Mapper.CreateMap&lt;MyObject, MyMappedObject&gt;()
      .ForMember(dest =&gt; dest.Url, opt =&gt; opt.MapFrom(src =&gt; Url.Content("~/something/") + src.Id));
  }
  </code></pre>
  
  <p>The first request works fine, but subsequent requests throw a NullReferenceException with the following stack trace:</p>
  
  <pre><code>at System.Web.HttpServerVarsCollection.Get(String name)
  at System.Web.Mvc.UrlRewriterHelper.WasThisRequestRewritten(HttpContextBase httpContext)
  at System.Web.Mvc.UrlRewriterHelper.WasRequestRewritten(HttpContextBase httpContext)
  at System.Web.Mvc.PathHelpers.GenerateClientUrlInternal(HttpContextBase httpContext, String contentPath)
  at System.Web.Mvc.PathHelpers.GenerateClientUrlInternal(HttpContextBase httpContext, String contentPath)
  at System.Web.Mvc.PathHelpers.GenerateClientUrl(HttpContextBase httpContext, String contentPath)
  at System.Web.Mvc.UrlHelper.GenerateContentUrl(String contentPath, HttpContextBase httpContext)
  at System.Web.Mvc.UrlHelper.Content(String contentPath)
  </code></pre>
  
  <p>The interesting part is if I cache the Url.Content() part before the mapping, things work fine:</p>
  
  <pre><code>protected override void Initialize(RequestContext requestContext) {
    base.Initialize(requestContext);
  
    var url = Url.Content("~/something/");
    Mapper.CreateMap&lt;MyObject, MyMappedObject&gt;()
      .ForMember(dest =&gt; dest.Url, opt =&gt; opt.MapFrom(src =&gt; url + src.Id));
  }
  </code></pre>
  
  <p>btw this code is simplified, but for my use case it is used as part of a json response, so I cannot move the Url.Content() part to a view.</p>
  
  <p>Is this an automapper issue, an MVC issue, or more likely something I'm doing incorrectly?  Is there a cleaner solution other than just "caching" the url part in a variable before the mapping code?</p>