首页 > 解决方案 > Nancy v2 中的 Nancy.Json.JsonSettings

问题描述

我正在从 Nancy 1.4.5 -> 2.0 升级我的项目

我有错误:

public class AppBootstrapper : AutofacNancyBootstrapper
{
    private readonly ILifetimeScope _scope;

    public AppBootstrapper(ILifetimeScope scope)
    {
        _scope = scope;
    }

    protected override ILifetimeScope GetApplicationContainer()
    {
        return _scope;
    }

    protected override void ApplicationStartup(ILifetimeScope container, IPipelines pipelines)
    {
        JsonSettings.MaxJsonLength = int.MaxValue;
        JsonSettings.RetainCasing = true;

        base.ApplicationStartup(container, pipelines);
    }
}

}

Error CS0103 The name 'JsonSettings' does not exist in the current context

我该如何解决这个问题?

标签: nancy

解决方案


我在类中添加了方法AppBootstrapper

public class AppBootstrapper : DefaultNancyBootstrapper
{
    public override void Configure(INancyEnvironment environment)
    {
        environment.Json(retainCasing: true);
    }
    ... other methods
}

并添加maxJsonLengthweb.config

<system.web.extensions>
  <scripting>
    <webServices>
      <jsonSerialization maxJsonLength="2147483647"/>
    </webServices>
  </scripting>
</system.web.extensions>

推荐阅读