我创造了一个
服务
它也是一个httpserver,我已经编写了HTML文件并将它们存储在同一个工作目录中的一个文件夹中,(比如
E:\My_project\Pages\home.html
)
我有一个library.cs文件在
E:\My_project\
. 在我的代码里我有这行,
string content = File.ReadAllText("Pages/home.html");
当我试图读这行时,我得到以下错误:
mscorlib: Could not find a part of the path 'C:\WINDOWS\system32\Pages\home.html'
早些时候,它适用于其他一些页面,当我单独硬编码主页并从这些目录中读取其他页面(如404.html)时。现在我已经将主页也添加到了页面文件夹中,我得到了这个错误。
我的问题是如何克服这个错误以及Windows为什么要转到
C:\Windows\System32
而不是在与文件相同的目录中查找。
注意:是的,我使用线程,服务使用多个线程。
代码:
图书馆
public static List<Route> GetRoutes() {
List<Route> routes = new List<Route>();
string content = File.ReadAllText("Pages/home.html");
routes.Add(new Route
{
Name = "Hello Handler",
UrlRegex = @"^/$",
Method = "GET",
Callable = (HttpRequest request) =>
{
return HttpBuilder.GetHome();
}
});
return routes;
}