nancy

How to adjust field names in Nancy model bindings?

帅比萌擦擦* 提交于 2019-12-05 23:29:41
问题 In a web application I use Nancy for creating a REST service. Unfortunately, in HTML our field names are lowercase ( firstName ), but the appropriate properties in .NET are uppercase ( FirstName ). Moreover, we have some fields that don't map 1:1, such as id that shall become TicketId in .NET. Now I have two question on this: Is Nancy case-sensitive or case-insensitive when it comes to field names? Does Nancy provide some sort of mapping for field names? 回答1: Support for this is there, but it

NancyFx RequiresAuthentication extension returns 303 and not 403

自古美人都是妖i 提交于 2019-12-05 18:40:18
I'm not sure if I'm doing something wrong or there's a bug of some kind. If it is a bug, then I'd think this would have cropped up immediately. Either way: I'm using the extension method RequiresAuthentication from here: https://github.com/NancyFx/Nancy/blob/9d3c650575cba109e620ab163f4fda26a0536036/src/Nancy/Security/ModuleSecurity.cs Which uses SecurityHooks https://github.com/NancyFx/Nancy/blob/9d3c650575cba109e620ab163f4fda26a0536036/src/Nancy/Security/SecurityHooks.cs Or the code specifically: public static void RequiresAuthentication(this INancyModule module) { module

NancyFX Catch All route

江枫思渺然 提交于 2019-12-05 11:53:52
问题 Does NancyFX supports ASP.NET MVC like 'Catch All' route? I need one, that basically match every URL. This is very handy for building up Single Page applications. Is that possible? 回答1: Yes, using Regex Get[@"/(.*)"] = parameters => { return View["viewname", parameters]; }; But you don't really need it for building a Single Page Application with NancyFX - you can just use Get and Post with all your routing logic and still have a single page app. 回答2: Tested in Nancy version 0.23.2 Get[@"/(.*)

Razor Compilation Error using NancyFX

浪子不回头ぞ 提交于 2019-12-05 10:26:16
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: 73 - The type or namespace name 'Black_Jack' could not be found (are you missing a using directive or

Copy Razor-Views for Self-hosting NancyFx?

旧街凉风 提交于 2019-12-05 07:19:14
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-mode, where caching is disabled by default . I know this is just a minor annoyance, but still an

Nancy testing project can't find views

坚强是说给别人听的谎言 提交于 2019-12-05 06:50:48
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 render the view. If I run the project normally the module finds the view. It's only when invoked from

Nancy fails to find static content in custom convention

本秂侑毒 提交于 2019-12-05 06:35:29
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; using Nancy.Conventions; using Nancy.Bootstrapper; using Nancy.TinyIoc; namespace MyApp { public

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

末鹿安然 提交于 2019-12-05 04:24:52
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 string (equivalent to string.IsNullOrEmpty() ). What I would prefer is to to have the extension method

When do you really need async on a web framework?

China☆狼群 提交于 2019-12-05 04:00:35
Async has become a buzzword in .net and MS have introduced it in Web API 2 so that more requests can be handled whilst others are waiting on IO to finish. Whilst I can see the benefit of this, is it really a concern? A x64 architecture has 30000+ threads in the Thread Pool so unless you have that many concurrent users on your website is async really required? Even if you have that many concurrent users without caching I'm pretty sure SQL Server will fall over with that many requests? Apart from it being shiny when is there a real need to have async routing on a web framework? Many of the other

Does Nancy.Testing support nested Razor views?

蓝咒 提交于 2019-12-05 02:55:58
问题 I have a unit test that attempts to sign-in with incorrect credentials and checks the resulting response body for some specific 'errorbox' html. This works just fine. [Fact] public void SignIn__Should_display_error_message_when_error_passed() { var browser = Fake.Browser(); var response = browser.Get("/signin", with => with.Query("error", "true")); response.Body["#errorBox"] .ShouldExistOnce() .And.ShouldBeOfClass("floatingError") .And.ShouldContain("invalid", StringComparison