小编Too*_*nia的帖子

'TimeZoneInfo'不包含'ConvertTimeFromUtc'的定义(DNX Core 5.0)

在升级到asp5之前,下面的代码工作正常.DNX Core 5.0不支持ConvertTimeFromUtc方法.有没有其他正确的方法来实现这一目标?

public DateTime GmtNow() {
    return TimeZoneInfo.ConvertTimeFromUtc(DateTime.UtcNow, TimeZoneInfo.FindSystemTimeZoneById("GMT Standard Time"));
}
Run Code Online (Sandbox Code Playgroud)

c# dnx asp.net-core

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

User.GetUserId()在控制器的构造函数中失败

我收到以下错误:值不能为空.参数名称:principal

如何在控制器的构造函数中访问Identity(userId)?我只能通过将失败的调用包装在一个函数中来实现它(下面突出显示).

我需要注射什么吗?

public class BaseController : Controller {
    protected readonly MylDbContext dbContext;
    protected readonly string userId;

    public BaseController(MylDbContext dbContext) {
        this.dbContext = dbContext;
        userId = User.GetUserId(); // fails here
    }

    public string GetUserId() {
        return User.GetUserId(); // works here
    }
}
Run Code Online (Sandbox Code Playgroud)

asp.net asp.net-core-mvc asp.net-core

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

使用提前输入时,在onblur事件期间选择值

我可以简单输入一个货币列表。当我开始键入内容并选择所需的值(或按TAB键)时,即会选择所需的值-直到此时一切都按需工作。

但是,如果我键入整个单词并在输入之外单击而不是选择值(onblur事件),那么即使我输入的值与过滤器值匹配,所选范围变量也不会更新,因此我的输入无效。我正在尝试做的是在onblur事件期间覆盖选定的值。

示例:如果我键入EUR而不点击TAB或从预输入下拉列表中选择EUR值,然后在输入之外单击,则EUR文本停留在输入内部,但所选值未定义。我希望所选的值保留EUR而不是未定义。我使用$ viewValue在onblur事件期间发送输入值。

HTML:

<input type="text" ng-model="selected" typeahead-editable="false" typeahead="currency for currency in currencies | filter:$viewValue" ng-blur="selectCurrency($viewValue)" />
<div>Selected: {{selected}}</div>
Run Code Online (Sandbox Code Playgroud)

JavaScipt:

angular.module('myApp', ['ui.bootstrap'])
.controller("mainCtrl", function ($scope) {
    $scope.selected = '';
    $scope.currencies = ['EUR', 'GBP', 'USD'];
    $scope.selectCurrency = function(test) {
        console.log(test); //outputs undefined instead of EUR
        //if (checkIfCurrencyExists(test, $scope.currencies)) { - will do the checks later
        $scope.selected = test;
        //}
    };
});
Run Code Online (Sandbox Code Playgroud)

在下面的JsFiddle中,您可以看到相同的场景,除了它具有美国州而不是货币。尝试输入阿拉巴马州,然后 …

javascript angularjs bootstrap-typeahead angular-ui-bootstrap

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

UserManager.ResetPasswordAsync 上出现“无法访问已处置对象”错误

执行userManager.ResetPasswordAsync时出现以下错误:

An unhandled exception occurred while processing the request.

ObjectDisposedException: Cannot access a disposed object.
Object name: 'TestDb'.
Microsoft.Data.Entity.DbContext.get_ServiceProvider()
Run Code Online (Sandbox Code Playgroud)

我简化了代码,使其更易于阅读。我在控制器生命周期中调用userManager两次。一次用于生成令牌,一次用于重置密码:

    private readonly UserManager<ApplicationUser> userManager;

    // controller's constructor
    public AuthController(UserManager<ApplicationUser> userManager) {
        this.userManager = userManager;
    }

    [AllowAnonymous, HttpPost]
    public async Task<ActionResult> ForgotPass(ForgotPassViewModel model) {
        //model checks

        var user = new UserQuery(db).GetUserByUserName(model.UserName);

        //check if user exists

        var token = await userManager.GeneratePasswordResetTokenAsync(user);
        var url = $"{config.Url}/auth/resetpass?user={user.Id}&token={WebUtility.UrlEncode(token)}";

        // send email with the reset url

        model.Success = "An email has been sent …
Run Code Online (Sandbox Code Playgroud)

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

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