小编Ken*_*ach的帖子

Powershell - 在https绑定上设置SSL证书

我正在尝试使用PowerShell在IIS站点上为自签名/本地证书设置SSL证书.

我创建了证书:

$newCert = 
       New-SelfSignedCertificate 
       -DnsName www.mywebsite.ru 
       -CertStoreLocation cert:\LocalMachine\My
Run Code Online (Sandbox Code Playgroud)

然后尝试设置SSL绑定:

get-item 
      cert:\LocalMachine\MY\$newCert.Thumbprint | 
      new-item -path IIS:\SslBindings\0.0.0.0!443
Run Code Online (Sandbox Code Playgroud)

如以下帖子所示:http://www.iis.net/learn/manage/powershell/powershell-snap-in-configuring-ssl-with-the-iis-powershell-snap-in

此处还显示: Powershell IIS7 Snap in将SSL证书分配给https绑定

我也尝试过:

get-item 
      cert:\LocalMachine\MY\$newCert.Thumbprint | 
      new-item -path IIS:\SslBindings\*!443
Run Code Online (Sandbox Code Playgroud)

无济于事,我没有在编辑站点绑定对话框中看到SSL证书集.

有什么想法吗?

iis powershell ssl certificate

21
推荐指数
1
解决办法
2万
查看次数

使用Ninject BindHttpFilter时的范围问题

我有一个WebApi服务,我正在尝试使用Ninject BindHttpFilter添加身份验证.

使用BindHttpFilter允许我将身份验证过滤器绑定到特定属性.AuthenticationFilter采用构造函数参数(IAuthenticationService),该参数本身由Ninject创建.

kernel.BindHttpFilter<AuthenticationHttpFilter>(System.Web.Http.Filters.FilterScope.Action)
    .WhenActionMethodHas<AuthenticationFilterAttribute>()
    .WithConstructorArgument("service", x => x.Kernel.Get<IAuthenticationService>());
Run Code Online (Sandbox Code Playgroud)

AuthenticationService的具体实现采用通过Ninject注入的构造函数参数INonceRepository:

public AuthenticationService(INonceRepository nonceRepository, ...)
Run Code Online (Sandbox Code Playgroud)

NonceRepository的具体实现采用通过Ninject注入的构造函数ISession:

public NonceRepository(ISession session)
Run Code Online (Sandbox Code Playgroud)

这是Ninject绑定的样子:

kernel.Bind<INonceRepository>().To<NonceRepository>();
kernel.Bind<IAuthenticationService>().To<AuthenticationService>()

var session = sessionFactory.OpenSession();

Bind<ISession>().ToMethod(c => session).InRequestScope();
Run Code Online (Sandbox Code Playgroud)

当代码运行时,AuthenticationService的具体实现只被实例化一次,因此NonceRepositiory只被实例化一次.这意味着ISession有效并打开第一个请求,但ISession在第二次调用时关闭,而AuthenticationService的构造函数从未被第二次调用.这似乎是一个范围问题,但我无法弄清楚什么没有正确的范围,以使每个请求重新创建AuthenticationService.

我试图将FilterScope.Controller中的BindHttpScope请求更改为FilterScope.Action(认为这会导致AuthenticationService的范围是每个Action调用创建的)但是没有解决它.

以下是有趣的代码点:

public class AuthenticationHttpFilter : IAuthenticationFilter
{
    private readonly IAuthenticationService authenticationService;

    public AuthenticationHttpFilter(IAuthenticationService service)
    {
        this.authenticationService = service;
    }

    public bool AllowMultiple { get; private set; }

    public Task AuthenticateAsync(HttpAuthenticationContext authenticationContext, CancellationToken cancellationToken)
    {
        authenticationService.DoAuth();
        return Task.FromResult(0);
    }

    public Task ChallengeAsync(HttpAuthenticationChallengeContext authenticationChallengeContext, CancellationToken cancellationToken)
    {
    ...
    }
}

public class …
Run Code Online (Sandbox Code Playgroud)

ninject asp.net-web-api2

5
推荐指数
1
解决办法
748
查看次数

标签 统计

asp.net-web-api2 ×1

certificate ×1

iis ×1

ninject ×1

powershell ×1

ssl ×1