nancy

Handle multiple binding errors from ModelBindingException in NancyFX when binding to JSON in Request.Body

余生长醉 提交于 2019-12-11 06:17:19
问题 I have a post route that accepts some JSON payload in the request body. Post["/myroute/}"] = _ => { try { var model = this.Bind<MyModel>(); } catch (ModelBindingException e) { //PropertyBindException list is empty here, //so only the first exception can be handled... } } If there are multiple invalid data types (i.e. if there are several int properties defined in MyModel, and a user posts strings for those properties), I would like pass back a nice list of these errors, similar to how would

In NancyFx Razor, how do I get the html of a rendered view inside an action?

佐手、 提交于 2019-12-11 03:43:53
问题 I have case like: In MVC3 Razor, how do I get the html of a rendered view inside an action? but I'm using NancyFx. Anybody known, how to do it? 回答1: I think, I find answare: in http://shanemitchell.ca/tag/nancyfx/ in that method, the html is in "var content". ViewLocationContext viewLocationContext = new ViewLocationContext() { Context = module.Context, ModuleName = module.GetType().Name, ModulePath = module.ModulePath }; var rendered = module.ViewFactory.RenderView(viewName, model,

C# helper classes to implement NTLM authorization

自闭症网瘾萝莉.ら 提交于 2019-12-11 02:45:47
问题 Currently I'm trying to solve my problem — which is implement NTLM authorization on my intranet site in the way how I think it should work, namely ask password only on certain pages. Not just hitting main page — so site should be divided on two pieces: available for all and restricted. The issue I'm using Nancy framework and it does not implement NTLM natively. But this will not stop the real cowboy programmer. So I'm trying to develop custom request / response sequence to accomplish this

Implementing Options HttpVerb

时间秒杀一切 提交于 2019-12-11 01:02:57
问题 I want to accept options requests from an angular website. Every endpoint (signup, login etc) needs to accept the options http verb. I will then add the following to the response header. After += ctx => { ctx.Response.WithHeader("Access-Control-Allow-Origin", "*"); ctx.Response.WithHeader("Access-Control-Allow-Headers", "accept, client-token, content-type"); ctx.Response.WithHeader("Access-Control-Allow-Methods", "POST, GET"); ctx.Response.WithHeader("Access-Control-Max-Age", "30758400"); };

Why does storing a Nancy.DynamicDictionary in RavenDB only save the property-names and not the property-values?

纵饮孤独 提交于 2019-12-10 22:04:13
问题 I am trying to save (RavenDB build 960) the names and values of form data items passed into a Nancy Module via its built in Request.Form . If I save a straightforward instance of a dynamic object (with test properties and values) then everything works and both the property names and values are saved. However, if I use Nancy's Request.Form then only the dynamic property names are saved. I understand that I will have to deal with further issues to do with restoring the correct types when

Why waiting a task returned from async method gets blocked?

拈花ヽ惹草 提交于 2019-12-10 19:36:24
问题 I'm working on a Nancy/ASP.Net project. I've tried to use WebRequest to get data from other web service and I've implemented the request in an async function. I find a problem that when I try to wait on a task returned from the function, it gets blocked indefinitely. The simplified code looks like this.. using System.Net; using System.Threading.Tasks; using Nancy; public class TestModule : NancyModule{ public TestModule() { Get["/"] = p => "Hello, world"; Get["/async/"] = p => { var req =

YSOD when passing complex type as razor model in NancyFX

可紊 提交于 2019-12-10 19:07:28
问题 I'm getting a YSOD when sending a model of type IEnumerable<string> to my Razor view in NancyFX. Everything works well if supply a string as the model, with the relevant @model statement in the view, so its working. The error is Unable to discover CLR Type for model by the name of System.Collections.Generic.IEnumerable. Ensure that the model passed to the view is assignable to the model declared in the view. What have I missed? View.cshtml @model System.Collections.Generic.IEnumerable<System

Why can I not register a custom JSON.Net implementation in Nancy?

佐手、 提交于 2019-12-10 16:56:43
问题 I have the following installed: <package id="Nancy" version="1.4.2" targetFramework="net4" /> <package id="Nancy.Owin" version="1.4.1" targetFramework="net4" /> <package id="Nancy.Serialization.JsonNet" version="1.4.1" targetFramework="net4" /> <package id="Newtonsoft.Json" version="7.0.1" targetFramework="net4" /> <package id="Owin" version="1.0" targetFramework="net4" /> And also: public sealed class Startup { public void Configuration(IAppBuilder app) { var options = new NancyOptions();

Tell Nancy to serialize enums into strings

浪尽此生 提交于 2019-12-10 16:53:43
问题 Nancy by default serialize enums into integers when generating JSON response. I need to serialize enums into strings. There is a way to customize Nancy's JSON serialization by creating JavaScriptPrimitiveConverter. For example this is what I did to customize serialization for ONE enum: Create the customization class: public class JsonConvertEnum : JavaScriptPrimitiveConverter { public override IEnumerable<Type> SupportedTypes { get { yield return typeof(MyFirstEnum); } } public override

Model validation with NancyFX

那年仲夏 提交于 2019-12-10 14:19:58
问题 I'm really get used with ASP.NET MVC approach: annotate model with corresponding attributes, MVC does validate it and updates ModelState.Errors, ModelState is available on View, so it is possible to show errors to user. I haven't found information on wiki how exactly it should be done for NancyFX. In sources I can see that Nancy trying to use Rules, but how to apply correctly and show failures on Views? EDIT : Question is relevant to Nancy 0.9, according to @TheCodeJunkie 0.10 will apply