nancy

How do you add htmlHelpers into the Spark virew

半腔热情 提交于 2019-12-24 01:54:59
问题 I want to use the htmlHelpers in my spark view but I keep getting the following errors. error CS0234: The type or namespace name 'Mvc' does not exist in the namespace 'System.Web' (are you missing an assembly reference?) I have added the System.Web.Mvc assembly into the project. I have also added the following code into the module (just for the sake of getting it working - I'll probably need to add this code to the bootstrapper --- not sure how to do that yet!) var settings = new

What to use instead of HttpContext when using OWIN without System.Web

馋奶兔 提交于 2019-12-23 19:20:03
问题 We currently have a NancyFx project that we have wired up using OWIN. We are not using System.Web and we need some place to put our context that lives for the life of a request other than HttpContext. We have started implementing the context on a thread static variable so we can access the context anywhere in the application but we are worried that using Async calls will lose this thread static context. What do you use as a static accessor in lue of HttpContext when you divorce yourself from

How to Prevent Nancy From Caching Views

℡╲_俬逩灬. 提交于 2019-12-23 08:54:50
问题 I've started testing out Nancy in self-host mode. So far, so good apart from one issue that's irking me: How do I prevent it from caching my views while developing? I did notice a comment that view caching is supposed to be disabled in Debug mode but it doesn't seem to be working for me - I have to restart my application whenever I make a change to the HTML. I'm using Nancy 0.10 with the built-in super simple view engine and .html files. 回答1: Caching is disabled by default in debug-mode. The

Nancy: Serving static content (e.g. index.html) from “/”?

不羁岁月 提交于 2019-12-23 06:58:56
问题 I'm trying to make a single page web application using Nancy. Therefore, I want my root URL to serve a plain .html file, without any view logic or whatsoever. I tried Get["/"] = parameters => Response.AsHtml("content/index.html") But there's no AsHtml . I tried a custom bootstrapper with conventions.StaticContentsConventions.Add( StaticContentConventionBuilder.AddFile("/", @"content/index.html") ); But apparently it thinks that "/" is not a file - Nancy gives me a directory listing on http:/

NancyFX: How do I check if query-string / form values have been correctly passed to my handler?

蹲街弑〆低调 提交于 2019-12-22 04:58:43
问题 Nancy passes my query-string and form values to my handlers via a dynamic variable. The example below shows form values being passed in to a POST handler via the Nancy request e.g. Request.Form.xxx . Handler Post["/"] = _ => { var userId = (string) Request.Form.userid; if (userId.IsEmpty()) return HttpStatusCode.UnprocessableEntity; return HttpStatusCode.OK; }; You can see that I am casting the userid to a string and then using a string extension method to check if the value is null or empty

File downloads in a self-host Nancy application

淺唱寂寞╮ 提交于 2019-12-21 13:06:20
问题 I'm working on a small project that uses Nancy hosted from within a WPF application. I want to be able to remotely download a PDF file that is ~8MB. I was able to get the download to work but while the download is in progress the application won't respond to any other requests. Is there a way I can allow the file download without tying up the all other requests? Public Class ManualsModule : Inherits NancyModule Public Sub New() MyBase.New("/Manuals") Me.Get("/") = Function(p) Dim model As New

Can self hosted SignalR on the Raspberry Pi work?

风流意气都作罢 提交于 2019-12-21 05:02:34
问题 I want to have a C#/mono/signalR based web page hosted on the Raspberry Pi - is this possible? I have managed to write a client-server-client solution where the signalR hub is hosted on a PC running IIS 8. A console app on the pi connects to the server hub with the c# signalR client. The asp.net server also hosts a 'remote control' page for a browser client to send commands to the pi but now I want to eliminate the PC as a requirement and have everything hosted on the pi. 回答1: TLDR It can be

How to display my 404 page in Nancy?

Deadly 提交于 2019-12-21 03:59:16
问题 I need to display my 404 error page in Nancy like this if (ErrorCode == 404) { return View["404.html"]; } How to do it? 回答1: The answer from nemesv is correct, but I just wanted to add an example using the ViewRenderer instead of the GenericFileResponse. public class MyStatusHandler : IStatusCodeHandler { private IViewRenderer viewRenderer; public MyStatusHandler(IViewRenderer viewRenderer) { this.viewRenderer = viewRenderer; } public bool HandlesStatusCode(HttpStatusCode statusCode,

Nancyfx self hosting over HTTPS

人走茶凉 提交于 2019-12-21 02:36:17
问题 I tried to start a nancyfx webserver in self hosting mode. Everything works fine when executing the following code: public static void Main(string[] args) { var hostConfig = new HostConfiguration { UrlReservations = new UrlReservations { CreateAutomatically = true }, }; var host = new NancyHost(hostConfig, new Uri("http://localhost:8081")); host.Start(); Console.ReadLine(); host.Stop(); } However, when I change the uri to https://... the server starts but every connection opened by the

Why are no query parameters being passed to my NancyFX module?

爱⌒轻易说出口 提交于 2019-12-18 19:42:11
问题 I am running a self-hosted NancyFX web server inside of my application. Right now I have one module hosted: public class MetricsModule : NancyModule { private IStorageEngine _storageEngine; public MetricsModule(IStorageEngine storageEngine) : base("/metrics") { _storageEngine = storageEngine; Get["/list"] = parameters => { var metrics = _storageEngine.GetKnownMetrics(); return Response.AsJson(metrics.ToArray()); }; Get["/query"] = parameters => { var rawStart = parameters.start; var rawEnd =