1

我有一个将公开公开的 api 并有一个沙箱。我已经在我的 ResourceFactory 中编写了一些代码,所以 api.sandbox.whatever/whatever 会起作用,并且参数中的 sandbox=true 也会起作用,但这感觉就像一个巨大的黑客攻击。有什么更好的方法吗?

这是我的代码:

public class NinjectResourceFactory : IResourceFactory
{
    private readonly IKernel _productionKernel;
    private readonly IKernel _sandboxKernel;

    public NinjectResourceFactory()
    {
        _productionKernel = new StandardKernel(new QueryMasterModule());
        _sandboxKernel = new StandardKernel(new QueryMasterModule(true));
    }

    public object GetInstance(Type serviceType, InstanceContext instanceContext, HttpRequestMessage request)
    {                        
        string uri = request.RequestUri.ToString();
        if (uri.Contains(".sandbox."))
        {
            return _sandboxKernel.Get(serviceType);
        }
        else if (uri.Contains("sandbox=true"))
        {
            request.RequestUri = new Uri(uri.Replace("sandbox=true", ""));
            return _sandboxKernel.Get(serviceType);
        }
        else
        {
            return _productionKernel.Get(serviceType);    
        }            
    }

    public void ReleaseInstance(InstanceContext instanceContext, object service)
    {
        // todo do I need to implement this?
    }
}
4

1 回答 1

0

如果它应该是一个真正的沙箱,那么您不希望这两个站点在同一个进程中运行。我会部署两个网站,让 IIS 根据主机名决定哪一个。这样沙盒将与生产隔离,这就是沙盒的目的。

于 2011-06-11T08:22:27.507 回答