小编Zer*_*One的帖子

将QueryString附加到asp.net核心Anchor Helper Tag中的href

我试图在html结果中向锚点添加请求查询中的任何内容:

虚构的例子:

用户发出请求(请注意,乐队和歌曲可以是任何内容,我有一条路径来满足此请求:模板:"{band}/{song}"):

http://mydomain/band/song?Param1=111&Param2=222
Run Code Online (Sandbox Code Playgroud)

现在我希望我的锚点将查询字符串部分附加到我的锚点的href.所以我试过这样的事情(注意'asp-all-route-data'):

<a asp-controller="topic" asp-action="topic" asp-route-band="iron-maiden" asp-route-song="run-to-the-hills" asp-all-route-data="@Context.Request.Query.ToDictionary(d=>d.Key,d=>d.Value.ToString())">Iron Maiden - Run to the hills</a>
Run Code Online (Sandbox Code Playgroud)

查询字符串的附加实际上与上面的代码一起使用,但随后结果中丢失了"铁娘子"和"跑到山上".上面的标签助手返回以下内容(注意帮助器如何将请求中的乐队和歌曲镜像到href中,而不是我在asp-route属性中指定的乐队和歌曲):

<a href="http://mydomain/band/song?Param1=111&Param2=2222">Iron Maiden - Run to the hills</a>
Run Code Online (Sandbox Code Playgroud)

我希望帮助者得到以下结果:

<a href="http://mydomain/iron-maiden/run-to-the-hills?Param1=111&Param2=2222">Iron Maiden - Run to the hills</a>
Run Code Online (Sandbox Code Playgroud)

看起来当我使用asp-all-route-data时,我在结果中丢失了asp-route-bandasp-route-song值.

有没有人偶然发现了这个?

谢谢

Hooroo

asp.net asp.net-mvc tag-helpers asp.net-core asp.net-core-tag-helpers

7
推荐指数
1
解决办法
1645
查看次数

jasmine.clock().tick()与$ timeout和debounce无效,但与setTimeout一起工作正常

下面我有3个完全相同的功能.每个使用不同的方式调用setTimeout,delay1()直接使用setTimeout,delay2()使用angularjs $ timeout和delay3()使用lodash debounce.他们都很好.

当我使用Jasmine进行测试时会出现问题.setTimeout可以正常使用jasmine.clock().tick()方法,但$ timeout和debounce不能

我有兴趣与Jasmine一起进行辩论.我知道我可以使用带有angularjs的$ timeout.flush()但$ timeout和setTimeout在我的代码中的其他地方给我带来问题,我在传单中使用它.debounce与传单很好地配合.

我在这里创建了一个plunker:plnkr,你会看到$ timeout和debounce测试在setTimeout测试通过时没有通过.

有没有办法解决这个问题?谢谢

JS

var app = angular.module('plunker', []);

app.controller('MainCtrl', function($scope, $timeout) {
  $scope.name = 'World';
  $scope.delayed1 = function(){
    setTimeout(function(){
      $scope.name = "Hello world by setTimeout";
    },500)
  }
  $scope.delayed2 = function(){
    $timeout(function(){
      $scope.name = "Hello world by $timeout";
    },500)
  }
  $scope.delayed3 = function(){
    _.debounce(function(){
      $scope.name = "Hello world by debounce";
    },500)
  }
});
Run Code Online (Sandbox Code Playgroud)

规范

describe('Testing a Hello World controller', function() {
  var $scope = null;
  var ctrl …
Run Code Online (Sandbox Code Playgroud)

javascript jasmine angularjs leaflet lodash

6
推荐指数
1
解决办法
6780
查看次数

如何在TypeScript中实现ng.IDirectiveFactory

我最近更新了我的typescript项目中的angular.d.ts文件.我现在在指令定义中得到一个打字稿编译错误.我在更新的angular.d.ts文件中注意到以下内容:

interface IDirectiveFactory {
    (...args: any[]): IDirective;
}
Run Code Online (Sandbox Code Playgroud)

我试图找出如何实现此接口.

我得到这个编译错误:类型ng.DirectiveFactory需要一个调用签名,但类型"MyDirective"缺少.

这就是我的指令现在看起来的样子(以前使用较旧的angular.d.ts文件可以正常工作):

class MyDirective{
    constructor() {
        var directive: ng.IDirective = <ng.IDirective>{};
        directive.priority = 0;
        directive.restrict = "E";
        directive.scope = {...};
        directive.template = '<div></div>';
        directive.link = {...}
        return directive;
    }
}
Run Code Online (Sandbox Code Playgroud)

这是我用angular注册MyDirective类的地方:

angular.module("MyModule", [])
        .directive('myDirective', MyDirective);
Run Code Online (Sandbox Code Playgroud)

上面的编译器错误很有意义,但是如何实现(... args:any []):IDirective签名)?

提前致谢

angularjs typescript angularjs-directive

5
推荐指数
2
解决办法
6959
查看次数

修改CookieAuthenticationOptions LoginPath OnRedirectToReturnUrl事件

我在MVC 6 ASP.NET 5项目中进行了以下设置:

配置方法中的Startup.cs:

app.UseCookieAuthentication(options =>
{
    options.AuthenticationScheme = "Cookie";
    options.LoginPath = new PathString("/<TENANT>/account/signin/");
    options.AccessDeniedPath = new PathString("/<TENANT>/account/unauthorised/");
    options.AutomaticAuthenticate = true;
    options.AutomaticChallenge = true;
    options.Events = new CookieAuthenticationEvents
    {
        OnRedirectToReturnUrl = MyClass.RedirectToReturnUrlAsync
    };
});
Run Code Online (Sandbox Code Playgroud)

活动课程:

public static class MyClass
{
    public static async Task RedirectToReturnUrlAsync(CookieRedirectContext context)
    {
        context.Options.LoginPath = new PathString("/<HERE I PLAN TO PUT LOGIC TO FIGURE OUT TENANT FROM CONTEXT>/account/signin");
    }

}
Run Code Online (Sandbox Code Playgroud)

让我们说用户转到以下网址:

http://localhost/mycompany/securecontroller/secureaction
Run Code Online (Sandbox Code Playgroud)

我希望Cookie中间件将用户重定向到:

http://localhost/mycompany/account/signin
Run Code Online (Sandbox Code Playgroud)

问题是当重定向返回Url时,代码"MyClass.RedirectToReturnUrlAsync"永远不会被命中,所以我找不到在运行时修改LoginPath的机会.

我怀疑我的设置有问题.有没有人遇到过这个问题?

Hooroo

c# authentication asp.net-mvc asp.net-core-mvc asp.net-core

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