簡體   English   中英

ServiceStack:自助主機找不到靜態文件

[英]ServiceStack: Self-Host Not finding static files

我有一個位於以下URI的自助服務:

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

注意 :我想將其托管在/PassengerTracker 這是最好的方法嗎?

我啟用了Razor視圖,並且在_Layout.cshtml文件中為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 ..

如果我將listeningOn更改為http://*: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

在聊天討論中,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(); 
    } 
}

我希望這對您有用:)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM