Nancy.Json.JsonSettings 南希 v2

Nancy.Json.JsonSettings in Nancy v2

我正在将我的项目从 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

我该如何解决这个问题?

我将方法添加到 AppBootstrapper class:

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>