nancy

How do I write streamed output in NancyFX?

旧街凉风 提交于 2019-12-04 05:54:23
I'm writing a simple web application using Nancy. At least one request results in a stream of unknown length, so I can't provide Content-Length . I'd like to use Transfer-Encoding: chunked , or (equally acceptable in this case, Connection: close ). I've had a quick hack on the Nancy source code, and I've add Response.BufferOutput , and code to set HttpContext.Response.BufferOutput to false . You can see that here: public class HomeModule : NancyModule { public HomeModule() { Get["/slow"] = _ => new SlowStreamResponse(); } private class SlowStreamResponse : Response { public SlowStreamResponse(

File downloads in a self-host Nancy application

半世苍凉 提交于 2019-12-04 05:16:01
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 List(Of String) From {"electrical", "opmaint", "parts"} Return View("Manuals", model) End Function Me

Nancy (C#): How do I get my post data?

我们两清 提交于 2019-12-03 22:23:45
I'm using Corona SDK to post data to my C# server: headers["Content-Type"] = "application/x-www-form-urlencoded" headers["Accept-Language"] = "en-US" local body = "color=red&size=small" local params = {} params.headers = headers params.body = body network.request( host .. "/UpdateHand", "POST", nwListener, params ) I receive a message on the server: Post["/UpdateHand"] = x => { Console.WriteLine("Received ..."); return "Ok"; }; But when I check the data (when I put a breakpoint on it) I don't see where my data is locaded (i.e. the params.body or params.headers). How can I extract this

Is it possible to enable CORS using NancyFX?

可紊 提交于 2019-12-03 18:24:30
问题 I have an API service made with NancyFX, and a couple of front-end developers creating an SPA JS client against this API. We would like to test the client side code against the published server without having to publish the client code with too much frequency. But, the client runs at localhost, and the server is at Windows Azure. Is it possible and easy to enable CORS on the NancyFX server? How can I do that? Thanks. 回答1: Its possible to do this in the bootstraper of Nancy protected override

Can self hosted SignalR on the Raspberry Pi work?

我只是一个虾纸丫 提交于 2019-12-03 15:49:56
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. TLDR It can be done! Video . Code . Long story I managed to get a solution working with Nancy , SignalR and the OWIN based

Get url parameters in NancyFx

馋奶兔 提交于 2019-12-03 14:25:31
问题 I am using NancyFx to build a web API, but I am facing some problems when getting parameters from the URL. I need to send, to the API, the request .../consumptions/hourly?from=1402012800000&tags=%171,1342%5D&to=1402099199000 and catch the value of the parameters: granularity, from, tags and to. I tried several approches and none worked. I tried, for example, Get["consumptions/{granularity}?from={from}&tags={tags}&to={to}"] = x => { ... } How can I do this? Luis Santos 回答1: There are 2 things

Redirect to ReturnUrl after successful cookie authentication in Owin, Katana & Nancy

一笑奈何 提交于 2019-12-03 13:33:18
I am using Owin, Katana and Nancy to host a simple site with an authentication required section. Note I am also using nuget package - Nancy.MSOwinSecurity app.UseCookieAuthentication(new CookieAuthenticationOptions { AuthenticationType = Constants.AuthenticationType, LoginPath = new PathString("/Login"), }); app.UseNancy(); Here is my module code public class LoginModule : NancyModule { public LoginModule() { Post["login"] = p => { var name = Request.Form.name; var auth = Context.GetAuthenticationManager(); var claims = new List<Claim> {new Claim(ClaimTypes.Name, name)}; var id = new

How to display my 404 page in Nancy?

一曲冷凌霜 提交于 2019-12-03 12:13:20
I need to display my 404 error page in Nancy like this if (ErrorCode == 404) { return View["404.html"]; } How to do it? 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, NancyContext context) { return statusCode == HttpStatusCode.NotFound; } public void Handle(HttpStatusCode statusCode

Return HttpStatusCode in the Response

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-03 10:58:29
Is there a easy way to return just a HttpStatusCode for my api? I've found a slightly more verbose way to do this return Response.AsJson(new object(), HttpStatusCode.NoContent); I've taken a look at the Response class's source code and I see public static implicit operator Response(HttpStatusCode statusCode) { ... } Is this what I'm looking for? If so how do I use it, what I'd really like would be able to do is return Response(HttpStatusCode.NoContent); You can just directly return a HttpStatusCode from your action: Get["/hello/"] = parameters => { return HttpStatusCode.NoContent; }; From the

Respond with both body and status code in Nancy

寵の児 提交于 2019-12-03 10:41:01
问题 I'm new to Nancy and I want to return both a custom HttpStatusCode and a body (content). If I return an HttpStatusCode, it returns it with a blank body. If I return a string then it returns that as the body but always with a 200 status code of OK. public class SendSMS : NancyModule { public SendSMS() { Post["/SendSMS"] = parameters => { return HttpStatusCode.BadRequest; // this works, no body return "Missing \"to\" parameter"; // this works, 200 status code // want to return status code with