5

I am developing an MVC Web API application that I need to access from web browsers on many different devices, for example, smart phones. During development I want to be able to debug while I access the site from my phone. To do this, I have set up Fiddler to provide a reverse proxy. Locally, the server is running on localhost:55950, but from my phone I can access the site as MyComputer:8888. This part is working.

The issue is that I am creating URIs in my REST responses. When I access the site at MyComputer:8888, I need the URIs to be something like MyComputer:8888/services/api/files, but instead I get localhost:55950/services/api/files, which fails on my phone. I am using the UrlHelper class to generate the URIs. I've looked all over, but haven't found a way to tell the system to use the referrer, not the local host. I see the desired Referrer value in the Request, so I think I could write code to patch the URI, but it seems like this would be a common issue and that there must be a way to get UrlHelper to work correctly.

I'd greatly appreciate it if anyone could point me in the right direction.

JSwartzen
  • 255
  • 1
  • 4
  • 12

1 Answers1

1

Check out this SO answer.

var httpContext = HttpContext.Current;

if (httpContext == null) {
  var request = new HttpRequest("/", "http://example.com", "");
  var response = new HttpResponse(new StringWriter());
  httpContext = new HttpContext(request, response);
}

var httpContextBase = new HttpContextWrapper(httpContext);
var routeData = new RouteData();
var requestContext = new RequestContext(httpContextBase, routeData);

return new UrlHelper(requestContext);
Community
  • 1
  • 1
Diego
  • 16,436
  • 26
  • 84
  • 136