我是否需要在应用程序Bootstrapper中添加任何配置代码以在Nancy中启用FluentValidation?
按照https://github.com/NancyFx/Nancy/tree/master/src/Nancy.Demo.Validation中的示例,我尝试在模型上使用this.Validate时收到以下异常消息:无法找到模型验证工厂.
我正在使用Nancy版本0.11.0.0
我需要在Nancy中显示我的404错误页面
if (ErrorCode == 404)
{
return View["404.html"];
}
Run Code Online (Sandbox Code Playgroud)
怎么做?
使用Nowin的美妙之处在于我不必乱用各种Windows命令来设置简单的Web服务器.根据Nowin自述文件,我可以使用以下行配置SSL
builder.SetCertificate(new X509Certificate2("certificate.pfx", "password"));
Run Code Online (Sandbox Code Playgroud)
但是,在使用Nancy时,我似乎无法访问此Server构建器类.一切似乎都在幕后神奇地发生.
我有什么想法可以将证书传递给Nowin吗?
我尝试在URL上创建一个带NancyModules和GET字符串的类,但方法'Get'告诉我:
"错误CS0021无法将[]索引应用于"方法组"类型的表达式...."
我的代码:
using System; using System.Collections.Generic; using System.Linq;
using System.Web; using Nancy; using System.Text;
namespace SinglePageApp1 {
public class BloodPresureNancy : NancyModule
{
public BloodPresureNancy()
{
// Get dasn't work
Get["/"] = _ => "Heloooo";
}
}
}
Run Code Online (Sandbox Code Playgroud)
我添加了引用:Nancy,Nancy.Hosting.asp,它无法正常工作.
Async已成为.net中的流行语,MS已在Web API 2中引入它,以便可以处理更多请求,而其他请求则等待IO完成.
虽然我可以看到这样做的好处,但这真的是一个问题吗?x64架构在线程池中有30000多个线程,所以除非您的网站上有很多并发用户真的需要异步?即使你有很多没有缓存的并发用户,我也很确定SQL Server会因为那么多请求而崩溃?
除了它是否真的需要在Web框架上进行异步路由时才会闪亮?
我有一个Windows服务,我使用OWIN和NancyFX来托管一个网站.在我服务的许多地方,我使用Unity将依赖项注入类,主要是服务.但是,如果我在任何Nancy模块中使用它们,依赖关系会被解析两次,因为Nancy使用自己的IoC容器(TinyIoC).
幸运的是,Nancy允许通过创建nancy bootstrapper来覆盖默认的IoC容器生成和现有容器的使用.但是如何将现有的IUnityContainer传递给引导程序?
基本上,我只需要启动OWIN就是......
WebApp.Start<MyOwinStarter>(url);
Run Code Online (Sandbox Code Playgroud)
如何将Unity容器传递给它以将其进一步传递给nancy bootstrapper?
我的模块中有一条路线应该接受代表博客帖子的JSON主体.问题是请求正文不是seralized.如果我调试我在请求上看到以下值:
this.Request.Body.Length: 93
x.Keys.Count: 0
Run Code Online (Sandbox Code Playgroud)
路线
Post["/Blog"] = x =>
{
var post = this.Bind<Post>(); //Breakpoint
PostService.Save(post);
return post;
};
Run Code Online (Sandbox Code Playgroud)
HTTP请求
POST /Blog HTTP/1.1
Host: localhost:57888
Content-Type: application/json
Cache-Control: no-cache
{ "Post": { "Title":"Hello", "Content":"World", "Created":"2014-04-26" } }
Run Code Online (Sandbox Code Playgroud) 我对Nancy很陌生,现在正在尝试使用Auth.期待完全实现Forms身份验证.
出于测试目的,我设置了3个模块.
其他模块:
public class OtherModule : NancyModule
{
public OtherModule() : base()
{
// Use global, module level authentication.
this.RequiresAuthentication();
Get["/other"] = _ =>
{
return "Other";
};
Get["/woot"] = _ =>
{
return "Woot";
};
}
}
Run Code Online (Sandbox Code Playgroud)
主要模块:
public class MainModule : NancyModule
{
public MainModule() : base()
{
Get["/yolo"] = _ =>
{
// Use per-route authentication.
this.RequiresAuthentication();
return "#YOLO";
};
}
}
Run Code Online (Sandbox Code Playgroud)
AuthModule:
public class AuthModule : NancyModule
{
public AuthModule() : base()
{
Get["/login"] = …Run Code Online (Sandbox Code Playgroud) 我试图让所有类型的请求与Nancy和CORS一起工作.目前我在请求结束时添加了一个管道:
pipelines.AfterRequest.AddItemToEndOfPipeline((ctx) => ctx.Response
.WithHeader("Access-Control-Allow-Origin", "http://localhost:57515")
.WithHeader("Access-Control-Allow-Methods", "POST, GET, DELETE, PUT, OPTIONS")
.WithHeader("Access-Control-Allow-Headers", "Accept, Origin, Content-type")
.WithHeader("Allow", "POST, GET, DELETE, PUT, OPTIONS"))
Run Code Online (Sandbox Code Playgroud)
选项请求返回状态代码为200,这使我相信它执行正常,但对于OPTIONS以外的任何类型的请求,它都会因405 Method Not Allowed而失败.还有什么我需要做客户端或服务器端才能使其工作?
我使用的客户端库是骨干.
提前致谢.
在一个没有编译的旧webform 站点项目中esclude使用管道中的aspx页面有一种方法吗?nancy.Owin
当我将nancy配置为post-back并且请求是一个aspx页面时,将删除post-back,因为nancy删除它并调用该页面.
public void NancyConfig(IAppBuilder app)
{
app.UseNancy(options =>
{
options.Bootstrapper = new MyBootstrapper();
options.PerformPassThrough = (context => context.Response.StatusCode == HttpStatusCode.NotFound);
});
app.UseStageMarker(PipelineStage.MapHandler);
}
Run Code Online (Sandbox Code Playgroud)
在options.PerformPassThrough擦后门柱的内容和调用页面.因为没有回发是好的,但是在后期详细说明中,这呈现出无限循环.
如何NancyFx在passtrought选项中配置不擦除回发?