nancy

How to serve static content in Nancy

三世轮回 提交于 2019-12-03 09:28:35
I'm having trouble serving up static content such as JavaScript in Nancy. For example using the self hosting sample I have added a test.js to the Views folder and added a <script type="text/javascript" src="test.js"></script> tag to the staticview.html page. If I view this page in the browser the JavaScript is executed correctly. However when I run the sample the JavaScript is not executed. If I view the page in FireBug I see that I'm getting a 404 error for test.js. I've tried adding Get["{file}"] = p => { string path = string.Format("Views/{0}", p.file); return Response.AsJs(path); }; and

How to use Autofac to resolve instance per request dependencies for types in a child lifetime scope created by Nancy

风格不统一 提交于 2019-12-03 09:15:02
We have several applications hosted in Windows services that self host a Nancy endpoint in order to expose instrumentation about the operation of the applications. We use Autofac as our IOC. Several repositories are registered into the root container in a core DLL shared by all applications; this container is then passed to Nancy as its container using a bootstrapper derived from the Nancy.Autofac.Bootstrapper . What we found was that when a web request is received by Nancy it resolves a request for a repository from the root container and this led to memory being consumed by non-garbage

Nancyfx self hosting over HTTPS

独自空忆成欢 提交于 2019-12-03 08:29:31
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 browser is instantly closed and the browser displays "The website is not available". The connection is even

Nancy model binding to child class

ぃ、小莉子 提交于 2019-12-03 07:02:33
We are having an issue with Nancy's default model binder. Given the below... public class Foo { public Foo() { } public string Name { get; set; } public Bar Bar { get; set; } } public class Bar { public string Name { get; set; } } with elements like... <input type="text" value="Name" /> <input type="text" value="Bar.Name" /> With the default model binder used like so.. var foo = this.Bind<Foo>(); This correctly binds Foo.Name but fails to bind Foo.Bar.Name Is there a way to enable this kind of binding with the default binder or do we need to roll our own? If so are there any good examples? Why

Benefits of using NancyFx? [closed]

夙愿已清 提交于 2019-12-03 06:30:55
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 6 years ago . There is yet another framework for making HTTP calls called NancyFx. My question is what are the benefits of using it. I had quick look at the documentation: https://github.com/NancyFx/Nancy/wiki/Documentation and it looks like there is no outstanding feature due to which I

Localization in Nancy without the razor viewengine

£可爱£侵袭症+ 提交于 2019-12-03 06:01:58
For the moment I'm using razor as my view engine in Nancy. I can access my resource file like this in razor: @Text.text.greeting But I would like to switch to a different view engine. Are there other view engines available that support the TextResource? How does localization works in the super simple view engine? Or is there a way to access the resources using the model? ctrlplusb Good question! This is something that I have needed to do myself. I managed to solve this problem using the basis of the suggestion made to you by @Karl-Johan Sjögren - i.e. I was able to create an extension to the

How should I handle authentication with Nancy?

独自空忆成欢 提交于 2019-12-03 05:49:08
问题 I started coding a LoginModule for Nancy, but it occurred to me that possibly I need to perform authentication a different way. Is there an accepted way of doing auth in Nancy? I am planning two projects right now: web and json service. I will need auth for both. 回答1: As Steven writes Nancy supports basic and form auth out of the box. Have a look these two demo apps to see how to do each: https://github.com/NancyFx/Nancy/tree/master/samples/Nancy.Demo.Authentication.Forms and https://github

Returning a string containing valid Json with Nancy

北城以北 提交于 2019-12-03 05:28:37
问题 I receive a string that contains valid JSON from another service. I would like to just forward this string with Nancy but also set the content-type to "application/json" which will allow me to remove the need for using $.parseJSON(data) on the client side. If I use Response.AsJson it seems to mangle the JSON in the string and adds escape characters. I could create a Stream with the string and set the response type something like: Response test = new Response(); test.ContentType = "application

How can I authenticate against Active Directory in Nancy?

不羁岁月 提交于 2019-12-03 05:13:54
问题 It's an outdated article, but http://msdn.microsoft.com/en-us/library/ff650308.aspx#paght000026_step3 illustrates what I want to do. I've chosen Nancy as my web framework because of it's simplicity and low-ceremony approach. So, I need a way to authenticate against Active Directory using Nancy. In ASP.NET, it looks like you can just switch between a db-based membership provider and Active Directory just by some settings in your web.config file. I don't need that specifically, but the ability

Respond with both body and status code in Nancy

99封情书 提交于 2019-12-03 01:10:46
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 message }; } } You could always create an instance of the Response type and set the Body and StatusCode