[英]ServiceStack: Self-Host Not finding static files
I have a self hosted service sitting at the following URI: 我有一个位于以下URI的自助服务:
const string listeningOn = "http://*:80/PassengerTracker/";
Note : I want to host it at /PassengerTracker
. 注意 :我想将其托管在
/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: 我启用了Razor视图,并且在
_Layout.cshtml
文件中为CSS静态文件指定了URL,如下_Layout.cshtml
:
<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
但是,这将返回404。我已将“
Copy to Ouput Directory
为Copy Always
If I try: 如果我尝试:
<link href="@(Request.GetApplicationUrl()
+ "/Content/bootstrap.min.css")" rel="stylesheet" />
I get a NotImplementedException
.. 我收到一个
NotImplementedException
..
If I change the listeningOn
to http://*:80/
. 如果我将
listeningOn
更改为http://*:80/
。 I can use @Url.Content
fine. 我可以使用
@Url.Content
很好。
I tried the following as per @Scott comment below: 我按照下面的@Scott评论尝试了以下内容:
<link href="@(AppHost.Config.ServiceStackHandlerFactoryPath
+ "/Content/bootstrap.min.css")" rel=" stylesheet" />
But it returns a 404: 但它返回404:
GET http://localhost:8090/passengertracker/PassengerTracker/Content/bootstrap.min.css
404
I noticed its putting PassengerTracker
twice? 我注意到它两次放置了
PassengerTracker
?
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. 在聊天讨论中,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();
}
}
This should work for you, I hope :) 我希望这对您有用:)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.