nancy

Nancy: how do I capture all requests irrespective of verb or path

北慕城南 提交于 2019-12-05 01:23:13
I want to use Nancy with the default routing, as it's clean and works well, however I want an option to log all incoming requests to the console (I'm using Nancy's self-hosting module) irrespective of whether an explicit route exists. Put simply, I want to be able to capture the verb, the incoming request URI, any posted data (if it's a POST request), etc. How do I do this? Before / After only seem to run for requests that match an existing route, and a 404 does not trigger OnError either. Also, using Get["/(.*)"] only catches GET requests and will ignore other HTTP verbs. Use the Before /

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

断了今生、忘了曾经 提交于 2019-12-04 16:43:37
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, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"; } public IEnumerable<string>

Return HttpStatusCode in the Response

試著忘記壹切 提交于 2019-12-04 16:03:40
问题 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); 回答1: You can just directly return a

How to serve static content in Nancy

无人久伴 提交于 2019-12-04 15:14:21
问题 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["

How do I manage my authentication with WorldDomination and Nancy?

放肆的年华 提交于 2019-12-04 12:05:59
问题 I'm trying to get social authentication working in an asp.net-hosted Nancy web app using the WorldDomination SimpleAuthentication plugin for Nancy. TL;DRs skip to the question bolded at the bottom of the question. Both are pretty nice, but there is a big documentation gap between the authentication process (well covered) and identifying the authenticated user during requests other than the initial authenticate request (nothing). Nancy provides for basic and forms authentication via additional

Localization in Nancy without the razor viewengine

喜你入骨 提交于 2019-12-04 10:29:52
问题 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? 回答1: Good question! This is something that I have needed to do myself. I managed to solve this problem using the basis of

Nancy - two modules listening on different ports

最后都变了- 提交于 2019-12-04 09:37:26
The idea is that I have two NancyModule classes that will be handling traffic on two different ports. For instance: FirstModule listening on localhost:8081 SecondModule listening on localhost:8082 I'm currently using Nancy.Hosting.Self to create Nancy instances on both localhost:8081 and localhost:8082 : internal static void Main(string[] args) { var uris = new Uri[] { new Uri("localhost:8081"), new Uri("localhost:8082"), }; var host = new NancyHost(uris); host.Start(); Console.ReadLine(); } How do I make class FirstModule : NancyModule listen only on port 8081 and SecondModule : NancyModule

SSL: NancyFx Selfhost Mono Linux (pi)

纵然是瞬间 提交于 2019-12-04 07:40:30
I am new to linux (PI) and mono, applogies for the newbie question How do I run NancyFx, shelf host, over https, on mono/linux/pi? If i am able to create a certificate using OpenSsl (cer file), how do I assign it to a port? in the docs show how to do this for windows (here https://github.com/NancyFx/Nancy/wiki/Accessing-the-client-certificate-when-using-SSL#configuration-of-hostingself ) thanks I have no knowledge of PI at all, but I assume it's not much different than hosting on any other variant of linux. There's two ways. The first is documented on the Wiki: https://github.com/NancyFx/Nancy

How to bind a model to a dynamically created class nancyfx

。_饼干妹妹 提交于 2019-12-04 06:18:30
问题 first of all thanks for anyone who's willing to have a look at my problem. I'm pretty new with Nancyfx and I'm having issues with trying to bind a JSON payload to a dynamically created class. I created the class dynamically by following the code in this post - Dynamically create a class in C# This is my block of code that creates the dynamic class, which I admit is essentially a cut and paste of the code given by danijels public static Type CompileResultType(List<Metadata> metadata) {

How to adjust field names in Nancy model bindings?

為{幸葍}努か 提交于 2019-12-04 06:15:40
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? Support for this is there, but it's not as fully featured as I'd like. If you take a look at the IFieldNameConverter interface (it's default