我有一个自托管的 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)
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) 我需要检查两个 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)