0

I have a self hosted service sitting at the following URI:

const string listeningOn = "http://*:80/PassengerTracker/";

Note: I want to host it at /PassengerTracker. Is this the best way to do it?

I have Razor Views enabled and I have specified the URL like so for my CSS static files in my _Layout.cshtml file:

<link href="@Url.Content("~/Content/bootstrap.min.css")" rel="stylesheet" />

However, this is returning a 404. I have set the Copy to Ouput Directory to Copy Always

Edit

If I try:

<link href="@(Request.GetApplicationUrl() 
               + "/Content/bootstrap.min.css")" rel="stylesheet" />

I get a NotImplementedException..

If I change the listeningOn to http://*:80/. I can use @Url.Content fine.

Edit 2

I tried the following as per @Scott comment below:

<link href="@(AppHost.Config.ServiceStackHandlerFactoryPath 
                      + "/Content/bootstrap.min.css")" rel=" stylesheet" />

But it returns a 404:

GET http://localhost:8090/passengertracker/PassengerTracker/Content/bootstrap.min.css 
404

I noticed its putting PassengerTracker twice?

Scott
  • 21,211
  • 8
  • 65
  • 72
CallumVass
  • 11,288
  • 26
  • 84
  • 154
  • What is the Url produced in the link when you view the outputted source of ``? Have you told ServiceStack where the handler path is `SetConfig(new EndpointHostConfig { ServiceStackHandlerFactoryPath = "/PassengerTracker" });`? – Scott Jun 18 '14 at 15:08
  • Yeah I set the Factory Path and the URL is: `http://localhost/Content/bootstrap.min.css` – CallumVass Jun 18 '14 at 15:28
  • Rather than `Request.GetApplicationUrl()` can you try `GetAppHost().Config.ServiceStackHandlerFactoryPath` so it is `` – Scott Jun 18 '14 at 15:34
  • Hey, Sorry was commuting home, give me 2mins.. I'll create a repro and test! :) – CallumVass Jun 18 '14 at 16:19
  • I've edited my question with an update – CallumVass Jun 18 '14 at 17:09
  • If you use `EndpointHost.Config.ServiceStackHandlerFactoryPath` and have you ensured that your `ServiceStackHandlerFactoryPath` starts with a `/` i.e. `/PassengerTracker` not just `PassengerTracker`, otherwise you would end up with a relative URL and it would be wrong. – Scott Jun 18 '14 at 17:14
  • Yup, it starts with a `/`: `SetConfig(new EndpointHostConfig { ServiceStackHandlerFactoryPath = "/PassengerTracker" });` – CallumVass Jun 18 '14 at 17:17
  • [Discuss in chat](http://chat.stackoverflow.com/rooms/55859/discussion-of-q24286368) – Scott Jun 18 '14 at 17:20

1 Answers1

3

From the chat discussion, there seems to be an issue with your ServiceStack's static file handler, so you could create a simple service that essentially performs the same task and serves the files from the Content directory.

[Route("/content/{filePath*}", "GET")] 
public class ContentRequest : IReturnVoid 
{ 
    public string filePath { get; set; } 
} 

public class ContentService : Service 
{ 
    public void Get(ContentRequest request) 
    { 
        var fullPath = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location), "Content", request.filePath); 
        Response.WriteFile(fullPath); 
        Response.End(); 
    } 
}

This should work for you, I hope :)

Scott
  • 21,211
  • 8
  • 65
  • 72
  • @BiffBaffBoff I am glad that worked. Yeah still rather odd though how it worked for me. – Scott Jun 18 '14 at 21:28
  • I did find an issue with this, it was returning the wrong MIME type which was causing an issue in IE. I've rectified it by setting the Response.ContentType appropriately based off of the file extension – CallumVass Jun 19 '14 at 08:25