ルーティングシステムを属性ルーティングに変更しました。なかでも私がHomeController
を追加しました:
[Route("")]
public class HomeController : Controller
{
[Route("")]
public IActionResult Index()
{
return View(); // The Home-page
}
[Route("Error")]
public IActionResult Error()
{
// show an error page
return Content(Activity.Current?.Id?.ToString() ?? HttpContext.TraceIdentifier.ToString());
}
[Route("{client}/{*tail}")]
[Produces("text/html")]
public IActionResult ClientApp(string client, string tail)
{
// show a client app
try
{
return new ContentResult()
{
Content = System.IO.File.ReadAllText($"./wwwroot/{client}/index.html"),
ContentType = "text/html"
};
}
catch
{
return RedirectToAction("/Error");
}
}
}
私のクライアントアプリケーションは、wwwroot
の内部に独自のフォルダ(client
ルーティング部分)の内側index.html
ファイルを持っていました。要求が/something/...
にアクセスしようとすると、ClientApp
のルートはクライアントアプリケーションのフォルダ名としてsomething
と一致し、index.html
がクライアントに送信されます。リダイレクトはなく、URLは同じままです。
は、それはあなたがStartup
にAddMvc
前UseStaticFiles
を追加する場合、静的ファイルで問題ない:ASP.NET MVCコア2.0でテスト
app.UseStaticFiles();
app.UseMvc();
。
asp.netコア2.0を使用している場合は、静的ページのRazorページを試してください。 https://docs.microsoft.com/en-us/aspnet/core/mvc/razor-pages/index?tabs=visual-studio – Ahmar
@Ahmar私はRazor Pagesを知っていますが、どのように役立つか分かりません。私はツールで生成されたHTMLファイルを取得し、余分なコントローラなどを避けたい – Koopakiller