小编Beh*_*ooz的帖子

AngularJS then()的行为与success()不同 - error()

由于AngularJS中的success()error()函数已弃用,我正在更新我的代码,将其替换为then().现在根据我的理解,这两段代码的行为应该相同:

$http
   .get(/* some params */)
   .success(function() {
      // success cases here
   })
   .error(function() {
      // error cases here
   });
Run Code Online (Sandbox Code Playgroud)

$http
   .get(/* some params */)
   .then(function() {
      // success cases here
   }, function() {
      // error cases here
   });
Run Code Online (Sandbox Code Playgroud)

但在某些情况下,我会得到不同的行为.你能否向我解释为什么会发生这种情况,更重要的是,保证使用then()函数的相同行为的方法是什么?

angularjs angular-promise

9
推荐指数
1
解决办法
4502
查看次数

如何在Asp.Net identity 2中手动检查密码?

这实际上可能更像是一个概念性问题.在Asp.Net Identity中,每次执行时,PasswordHasher都会为同一个字符串生成不同的哈希:

new PasswordHasher.HashPassword("myString");
Run Code Online (Sandbox Code Playgroud)

现在,如果由于某种原因我需要手动将用户的输入与数据库中保存的密码进行比较,那么当我散列用户输入的密码时,我很可能会得到一个不同的字符串,而不是存储在数据库中的密码.

有人可以向我解释一下吗?不应该在相同的散列中散列相同的字符串,如果不是,Identity本身如何实现两个不同的散列实际上是相同的?

asp.net hash password-encryption asp.net-identity asp.net-identity-2

8
推荐指数
2
解决办法
6724
查看次数

Angular 5文件上传:无法在“ HTMLInputElement”上设置“ value”属性

我有一个用于在angular 5应用程序中上载文件的表单,并且由于我完全是从前一阵子编写的代码中复制出来的,所以我可以保证它以前曾经工作过。

这是我的HTML代码:

<form [formGroup]="form" (ngSubmit)="onSubmit()">
        <div class="form-group">
            <label>File:</label>
            <input #theFile type="file" (change)="onFileChange($event)" accept=".png" class="form-control" 
                    formControlName="content" />
            <input type="hidden" name="fileHidden" formControlName="imageInput"/>

                    <!-- [(ngModel)]="model.content" -->

            <div class="alert alert-danger" *ngIf="!form.prestine && form.controls.content.errors?.noFile">
                Please provide a photo.
            </div>
            <div class="alert alert-danger" *ngIf="form.controls.content.errors?.fileTooBig">
                The file is too big and won't uploaded. Maximum allowed size is 500kb.
            </div>
        </div>
        <div class="form-group">
            <label>Notes</label>
            <textarea type="text" class="form-control" formControlName="notes" [(ngModel)]="model.notes" > </textarea>
        </div>
        <button type="submit" class="btn btn-primary" [disabled]="!form.valid">Submit</button>
        <button class="btn btn-default" type="button" (click)="close(false);">Cancel</button>
    </form>
Run Code Online (Sandbox Code Playgroud)

这是fileUpload控件中使用的“ onFileChange”方法:

onFileChange($event)
  { …
Run Code Online (Sandbox Code Playgroud)

html forms input angular angular5

8
推荐指数
4
解决办法
3万
查看次数

在Web Api 2中授予刷新令牌时更新角色

我已经在Asp.Net Web Api 2中开发了一个认证机制,它具有授予刷新令牌的功能,基于Taiseer博客上的教程.

这是我的问题.假设以下情形:用户使用密码登录并获取刷新令牌和访问令牌.访问令牌实际上包括他所处的角色(因此他在应用程序中的权限).同时系统管理员将更改此人的角色,因此一旦他的访问令牌到期并且他想使用刷新令牌获取新的访问令牌,他的新访问令牌必须包括新更新的角色.

在我的"RefreshTokenProvider"类中,我使用"GrantResourceOwnerCredentials"方法中的以下代码从数据库中获取用户角色并将其添加到声明中:

var roleManager = new RoleManager<IdentityRole>(new RoleStore<IdentityRole>(new ApplicationDbContext()));
        var y = roleManager.Roles.ToList();

        var id = new ClaimsIdentity(context.Options.AuthenticationType);
        id.AddClaim(new Claim(ClaimTypes.Name, context.UserName));
        id.AddClaim(new Claim("sub", context.UserName));

        var roles2 = UserRoleManagerProvider.RoleManager().Roles.ToList();

        foreach (IdentityRole i in roles2)
        {
            if (roleIds.Contains(i.Id))
                id.AddClaim(new Claim(ClaimTypes.Role, i.Name));
        }
Run Code Online (Sandbox Code Playgroud)

这件作品很好(即使我相信应该有更好的方法吗?!)

但是,无法正常工作的部分是在"GrantRefreshToken"方法中,我们需要更新角色以便在新的访问令牌中反映它们:

var newId = new ClaimsIdentity(context.Ticket.Identity);

        // *** Add shit here....

        var userId = context.Ticket.Properties.Dictionary["userId"];
        IdentityUser user = UserRoleManagerProvider.UserManager().FindById(userId);

        foreach (Claim c in newId.Claims)
        {
            if (c.Type == ClaimTypes.Role) newId.RemoveClaim(c);
        }

        if …
Run Code Online (Sandbox Code Playgroud)

authentication oauth access-token asp.net-web-api2 asp.net-identity-2

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

如何在Web Api 2中使用ThinkTecture IdentityServer 3

我已经阅读了很多关于如何在Asp.Net Web Api 2中实现完整的身份验证和授权系统的内容,其中包括注册,发送电子邮件确认,发出访问令牌和刷新令牌等等.毕竟我已经成功完成了所有这些工作.然而,对于每一个项目来说,它看起来都是不必要的.

我仍然不确定,但我相信"Thinktecture IdentityServer"是一个包装,已经整合在一起提供所有这些,我是对的吗?

如果是的话,任何人都可以(以非常直接的方式)告诉我如何创建一个新的Web Api项目并使用此软件包轻松获得上述所有功能?

security authentication thinktecture-ident-server asp.net-web-api2 thinktecture

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

在 .Net Core 中创建自定义 Sdk

在 .Net 核心项目中,有一个.csproj文件,其中第一行指定您在该项目中定位的 SDK,类似于:

<Project Sdk="Microsoft.NET.Sdk.Web">
Run Code Online (Sandbox Code Playgroud)

我的问题是是否有可能创建一个全新的 SDK(也许通过扩展Microsoft.NET.Sdk.Web)然后在其他一些项目中使用这个新的自定义 SDK,这样新项目的文件中就会有这样的内容.csproj

<Project Sdk="My.Own.Sdk">
Run Code Online (Sandbox Code Playgroud)

怎么可能做这样的事情?

sdk visual-studio .net-core

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

如何跳过HTTP请求的angularjs拦截器?

我有一个angularjs应用程序,其中我有一个拦截器,它将授权令牌添加到每个请求的标头中.

但是,我需要使用的应用程序中的某个地方以及拦截器对其进行破坏的外部API,因为它添加了此外部API提供程序无法接受的此授​​权标头.我怎样才能使angularjs HTTP跳过拦截器,只针对这一个具体情况?

拦截器代码如下:

app.factory('authInterceptorService', ['$q', '$injector', '$location', 'localStorageService', function ($q, $injector, $location, localStorageService) {
    var authInterceptorServiceFactory = {};
    var $http;

    var _request = function (config) {

        config.headers = config.headers || {};

        var authData = localStorageService.get('authorizationData');
        if (authData) {
            //console.log("token: " + authData.token.substring(0, 10));
            //console.log("user: " + authData.userName);
            config.headers.Authorization = 'Bearer ' + authData.token;
        }
        return config;
    }

    var _responseError = function (rejection) {
        var deferred = $q.defer();
        if (rejection.status === 401) {
            var authService = $injector.get('authService');
            authService.refreshToken().then(function (response) { …
Run Code Online (Sandbox Code Playgroud)

interceptor angularjs angularjs-http

4
推荐指数
3
解决办法
5856
查看次数

子路由上Azure上的Angular2应用“您无权查看此目录或页面”

我已经发布了Angular2应用并将其部署在Azure Web Apps上。如果通过浏览到其根目录来启动该应用程序,则该应用程序可以正常工作:http : //cafeserver.azurewebsites.net/Web/

但是,如果我直接浏览到应用程序中的子路由,例如以下示例:http : //cafeserver.azurewebsites.net/Web/customers

它将引发错误,指出“您没有查看此目录或页面的权限”。

我该如何解决这个问题?

iis azure angular2-routing angular

4
推荐指数
1
解决办法
2447
查看次数

ASP.NET MVC多对多关系,使用"My Own"表

我对使用Code First方法和实体框架相当新,我知道我有很多关系,比如下面的实体,EF会自动创建中间表:

class Post {
  ...
  public virtual ICollection<Category> Categories {get; set;}
  ... 
}

class Category {
   ...
   public virtual ICollection<Post> Posts {get; set;}
   ...
}
Run Code Online (Sandbox Code Playgroud)

但是,如果在中间表中我需要有额外的数据字段,一种可能的方式(我目前喜欢,也许是因为我不知道更好的方法)将定义我自己的新实体,如:

class Posts_Categories {
   public int Id {get; set;}
   public int CategoryId {get; set;}
   public int PostId {get; set;}
   public string Exrtafield1 {get; set;}
   public int ex extraField2 {get; set;}
   ...
   public virtual Post Post {get; set;}
   public virtual Category Category {get; set;}
}
Run Code Online (Sandbox Code Playgroud)

使用这种方法,EF确实创建了我的自定义中间表,但它还创建了另一个自己的名为"PostsCategories",它只包含Post_Id的外键和Category_Id的另一个外键.

如何让它不创建额外的一个并使用我定义的那个?这是管理多对多关系与额外数据字段的好方法吗?

asp.net-mvc many-to-many ef-code-first entity-framework-6

3
推荐指数
1
解决办法
2530
查看次数

CORS适用于访问令牌,但不适用于Web Api 2中的刷新令牌

我有一个Web API 2应用程序,我使用angularjs客户端调用该应用程序。Web API应用程序能够发出访问令牌并刷新令牌以进行身份​​验证。

“ GrantResourceOwnersCredentials”方法中包含以下几行,CORS可以正常工作以允许发布访问令牌:

var allowedOrigin = context.OwinContext.Get<string>("as:clientAllowedOrigin");
  if (allowedOrigin == null) allowedOrigin = "*";
  context.OwinContext.Response.Headers.Add("Access-Control-Allow-Origin", new[] { allowedOrigin });
Run Code Online (Sandbox Code Playgroud)

但是,当我尝试通过angularjs应用发布刷新令牌时,在控制台中出现了这个旧错误:

OPTIONS http://localhost:65141/token
(index):1 XMLHttpRequest cannot load http://localhost:65141/token. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:56815' is therefore not allowed access. The response had HTTP status code 400.
Run Code Online (Sandbox Code Playgroud)

我想知道随着访问令牌的发布正常,刷新令牌也使用相同的端点发布,我该怎么做才能克服这个问题?

顺便说一句,角度代码很好。我禁用了谷歌浏览器网络安全,然后一切正常!任何帮助是极大的赞赏!

authentication cors access-token angularjs asp.net-web-api2

3
推荐指数
1
解决办法
1279
查看次数

Identity Server 4 - 在数据库中保存刷新令牌

我在 .Net Core 2.0 中使用 IdentityServer4 并且我成功生成了访问令牌和刷新令牌。我只需要能够在生成时在服务器端“看到”刷新令牌,以便我可以将其保存在数据库中以用于某些特定目的。

在服务器上生成刷新令牌时,如何访问它的值?

c# identityserver4 refresh-token asp.net-core-2.0

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