有没有一种方法可以使用ServiceTask在控制台应用程序中托管Razor页面? [英] Is there a way to host Razor pages in console application using ServiceTask?

查看:78
本文介绍了有没有一种方法可以使用ServiceTask在控制台应用程序中托管Razor页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试制作一个控制台应用程序以公开JSON服务. 另外,我想托管html和js页面以使用它们. 我将* .md(甚至* .htm)文件放入Views文件夹中,但无法访问它们.

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.

如果我添加路由".Add("/Test")(其中MyMarkdownView:MarkdownViewBase),我什至会收到"KeyNotFoundException给定的键在字典中不存在".

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.

通常是否可以,或者我应该提供自己的服务(类似于 https://github.com/jimschubert/blogs/blob/master/2012-07-15/RazorExample/Main.cs )托管它们?

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?

推荐答案

您可能对

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.

即示例项目显示了在ServiceStack中托管MVC Razor页面的3种不同方式:

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

  1. 服务/控制器和模型-使用没有服务/控制器-直接使用请求DTO 作为视图模型
  2. 没有服务/控制器或模型-通过使用动态视图模型
  3. 直接直接
  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

这篇关于有没有一种方法可以使用ServiceTask在控制台应用程序中托管Razor页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆