0

我有一个位于以下 URI 的自托管服务:

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

注意:我想在/PassengerTracker. 这是最好的方法吗?

我启用了 Razor 视图,并为我的文件中的 CSS 静态文件指定了 URL _Layout.cshtml

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

但是,这将返回 404。我已将其设置Copy to Ouput DirectoryCopy Always

编辑

如果我尝试:

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

我得到一个NotImplementedException..

如果我更改listeningOnhttp://*:80/. 我可以@Url.Content很好地使用。

编辑 2

我根据下面的@Scott 评论尝试了以下操作:

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

但它返回 404:

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

我注意到它的推杆PassengerTracker两次?

4

1 回答 1

3

从聊天讨论来看,您的 ServiceStack 的静态文件处理程序似乎存在问题,因此您可以创建一个简单的服务,该服务基本上执行相同的任务并提供Content目录中的文件。

[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(); 
    } 
}

这应该对你有用,我希望:)

于 2014-06-18T20:46:19.877 回答