小编Kai*_*Kai的帖子

Owin 自托管 WebApi Windows 身份验证和匿名

我有一个自托管的 Owin WebAPI。我想通过身份验证保护一些路由。大多数路由应该可以匿名访问。我已经成功实现了 Windows-Auth,但是现在我401 - Unauthorized在尝试访问标记为[AllowAnonymous]匿名访问它们的路由时得到了。如果我使用有效凭据调用该方法,则一切正常。

完美的解决方案是默认允许匿名,并且仅在操作具有该[Authorize]属性时才需要凭据。

欧文配置

public void Configuration(IAppBuilder appBuilder)
{
    // Enable Windows Authentification
    HttpListener listener = (HttpListener)appBuilder.Properties["System.Net.HttpListener"];
    listener.AuthenticationSchemes = AuthenticationSchemes.IntegratedWindowsAuthentication;

    HttpConfiguration config = new HttpConfiguration();
    config.MapHttpAttributeRoutes();

    appBuilder.Use(typeof(WinAuthMiddleware));
    appBuilder.UseWebApi(config);
}
Run Code Online (Sandbox Code Playgroud)

WinAuth Owin 中间件

public class WinAuthMiddleware : OwinMiddleware
{
    public WinAuthMiddleware(OwinMiddleware next) : base(next) {}
    public async override Task Invoke(IOwinContext context)
    {
        WindowsPrincipal user = context.Request.User as WindowsPrincipal;
        //..
    }
}
Run Code Online (Sandbox Code Playgroud)

示例操作

public class ValuesController : ApiController
{      
    [AllowAnonymous] // attribute …
Run Code Online (Sandbox Code Playgroud)

c# windows-authentication self-hosting asp.net-web-api owin

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

2 条 SVG 路径的交集

我需要检查两个 SVG Path 元素是否相交。检查边界框与 的交集.getBBox()太不准确。我目前正在做的是迭代两条路径,.getTotalLength()然后检查两个点.getPointAtLength()是否相等。

下面是一个片段,但正如您所看到的,这非常慢并且会阻止浏览器选项卡。必须有一种更有效的方法来检查两条路径之间的交叉点。

var path1 = document.getElementById("p1");
var path2 = document.getElementById("p2");
var time = document.getElementById("time");
var btn = document.getElementById("start");
btn.addEventListener("click", getIntersection);

function getIntersection() {
var start = Date.now();
  for (var i = 0; i < path1.getTotalLength(); i++) {
    for (var j = 0; j < path2.getTotalLength(); j++) {
      var point1 = path1.getPointAtLength(i);
      var point2 = path2.getPointAtLength(j);

      if (pointIntersect(point1, point2)) {
        var end = Date.now();
        time.innerHTML = (end - start) / 1000 …
Run Code Online (Sandbox Code Playgroud)

javascript svg intersection

3
推荐指数
2
解决办法
5410
查看次数