nancy

Stream an (SqlFile-)Stream using Nancy

假装没事ソ 提交于 2019-12-08 03:08:28
问题 I was wondering how to send an (in my case) SqlFileStream directly to the client through our Nancy-API without loading the stream in memory. So far I succeeded in passing the stream, but Nancy's StreamResponse copies the sourcestream (=SqlFileStream) to the outputstream which causes a massive memory increase. Where I would just like it to send the stream through. I made this work in WebApi where WebApi was registered in the Owin-pipeline. No memory increase is noticeable, which is great when

How to serialize DateTimeOffset as JSON in NancyFX?

六眼飞鱼酱① 提交于 2019-12-08 03:02:29
问题 I'm attempting to return some JSON from my Nancy application, using the default JSON serializer. I've got the following DTO class: class Event { public DateTimeOffset Timestamp { get; set; } public string Message { get; set; } } When I return it, as follows: return Response.AsJson( new Event { Message = "Hello", Timestamp = DateTime.UtcNow }); ...I get all of the DateTimeOffset properties returned, so it looks like this: "Timestamp": { "DateTime":"\/Date(1372854863408+0100)\/", "UtcDateTime":

NancyFx on IIS and Windows Authentication

烈酒焚心 提交于 2019-12-08 02:04:08
问题 I have converted a MVC + AngularJS application to use NancyFx + AngularJS (as I wasn't really using any MVC stuff). I am using VS2013 and it runs under IIS (and IIS Express in my dev environment). I can obtain the current logged in user by examining the server.User component of the OwinEnvironment. I am currently using Microsoft.Owin.Host.SystemWeb as per most of the demos. When I add a RequiresAuthentication to a Get request in my module, I get a pop-up in IE to enter credentials even though

Razor Compilation Error using NancyFX

两盒软妹~` 提交于 2019-12-07 06:46:05
问题 I am creating a black jack program in C# utilizing Nancyfx and the Razor view engine in Visual Studio 2012. Visual studios Intelisense works but I get these Razor compiling errors. I have tried specifying the name space in app/web.config with no results. Error Details Error compiling template: Views/Game.cshtml Errors: [CS0246] Line: 1 Column: 11 - The type or namespace name 'Black_Jack' could not be found (are you missing a using directive or an assembly reference?) [CS0246] Line: 24 Column:

Nancy fails to find static content in custom convention

不羁的心 提交于 2019-12-07 03:35:48
问题 I've set up a Nancy bootstrapper to serve static content from a non-default directory path (it's self hosted Nancy). Strangely, the following works for the custom View location convention but not either of the js or css static content conventions (and yes, both files and folders exist at these locations!). My attempts at trying to resolve this are further compounded as I haven't figured out how to log errors which occur when static content is not found. using System; using System.IO; using

Nancy testing project can't find views

夙愿已清 提交于 2019-12-07 03:16:29
问题 Hit a bit of a stumbling block when trying to test a Nancy module from a test project. My test code looks pretty standard: [TestMethod] public void Should_return_status_ok_when_route_exists() { // Given var bootstrapper = new DefaultNancyBootstrapper(); var browser = new Browser(bootstrapper); // When var result = browser.Get("/", with => { with.HttpRequest(); }); // Then Assert.AreEqual(result.StatusCode, HttpStatusCode.OK); } I get an unable to locate view exception when my module tries to

Copy Razor-Views for Self-hosting NancyFx?

坚强是说给别人听的谎言 提交于 2019-12-07 03:09:34
问题 I started out with a simple MVC-site using NancyFx with Razor-views ( .cshtml ) and Nancy.Hosting.Aspnet , using IIS Express. Now I adapted the project to a self-hosting service using Nancy.Hosting.Self (and TopShelf). However, to provide the Views, it seems I need to change their properties from None & Do not copy to Content & Copy if newer , so they are copied to .\bin\Debug\ . One consequence is that changes to the Views will not be shown/updated until a restart. Even when working in debug

Can't get System.Web.Optimization to run with Nancy Self Hosting

浪尽此生 提交于 2019-12-06 09:09:55
问题 Has anyone had any luck using System.Web.Optimization with Nancy Self Hosting? If I comment out "Styles.Render("~/csspack/logincss").ToString()" the view works fine. If I leave it in a blank page is sent to the browser. This is what my Razor config looks like. public class RazorConfig : IRazorConfiguration { public IEnumerable<string> GetAssemblyNames() { yield return "Microsoft.Web.Infrastructure"; yield return "WebGrease"; yield return "System.Web.Optimization"; yield return "System.Web,

NancyFx Authentication per Route

淺唱寂寞╮ 提交于 2019-12-06 06:31:34
问题 From what I saw in the source code RequiresAuthentication() does an Authentication check for the whole module. Is there any way to do this per Route? 回答1: I had the same problem. However it turns out the RequiresAuthentication works at both the module level and the route level. To demonstrate, here is some code ripped out my current project (not all routes shown for brevity). public class RegisterModule : _BaseModule { public RegisterModule() : base("/register") { Get["/basic-details"] = _ =>

How do I write streamed output in NancyFX?

本小妞迷上赌 提交于 2019-12-05 23:45:14
问题 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"] = _