Is there a way to host Razor pages in console appl

2019-02-15 05:40发布

问题:

I'm trying to make a console application to expose JSON services. In addition I'd like to host html and js pages to use them. I put the *.md (even *.htm) files into Views folder, but I can't reach them.

If I add a route ".Add("/Test")" (where MyMarkdownView : MarkdownViewBase), i even get a "KeyNotFoundException The given key was not present in the dictionary." exception.

Is it generally possible, or I should make my own service (similar to https://github.com/jimschubert/blogs/blob/master/2012-07-15/RazorExample/Main.cs) to host them?

回答1:

You might be interested in the Razor Rockstars Console Application that uses embedded resource MVC Razor views that work with (or without) existing ServiceStack web services.

i.e. the example project shows the 3 different ways to host MVC Razor pages in ServiceStack:

  1. Service/Controller and Model - Using the Response DTO from the Web Service as a view model
  2. No Service/Controller - Directly using the Request DTO as the view model
  3. No Service/Controller or Model - Directly by using a dynamic view model