相关疑难解决方法(0)

没有注册IUserTokenProvider

我最近更新Asp.Net Identity Core了我的申请表1.0到2.0.

有一些我想尝试的新功能GenerateEmailConfirmationToken,等等.

我正在使用这个项目作为参考.

当用户尝试注册时,我在执行Register方法时遇到错误

private readonly UserManager<ApplicationUser> _userManager;     

public ActionResult Register(RegisterViewModel model)
{
    if (ModelState.IsValid)
    {
        var ifUserEXists = _userManager.FindByName(model.EmailId);
        if (ifUserEXists == null) return View(model);
        var confirmationToken = _userRepository.CreateConfirmationToken();//this is how i'm generating token currently.                
        var result = _userRepository.CreateUser(model,confirmationToken);
        var user = _userManager.FindByName(model.EmailId);
        if (result)
        {
            var code = _userManager.GenerateEmailConfirmationToken(user.Id);//error here
            _userRepository.SendEmailConfirmation(model.EmailId, model.FirstName, confirmationToken);
            //Information("An email is sent to your email address. Please follow the link to activate your account.");
            return …
Run Code Online (Sandbox Code Playgroud)

c# asp.net asp.net-identity-2

98
推荐指数
7
解决办法
4万
查看次数

如何在Azure网站上设置machineKey

我正在运行Azure网站.每当我部署时,每个人都会因为machineKey更改而退出.

我指定machineKeyweb.config,但是这并没有解决问题.我相信这是因为Azure会自动覆盖machineKey [1].

我在这里找到了几个类似的问题,但答案链接到死链接.

那么,解决方案是什么?当然,无论Azure上的部署如何,都有办法让用户登录.

asp.net authentication azure machinekey

28
推荐指数
2
解决办法
8671
查看次数

使用OWIN/Katana在Azure上的数据保护操作不成功

我正在尝试在Azure中运行的基于OWIN/Katana的ASP.NET MVC网站上实现密码重置.

它在本地运行时工作正常但在生产中失败.

我创建了一个UserToken提供程序

userManager.UserTokenProvider = new DataProtectorTokenProvider<ApplicationUser>(provider.Create("PasswordReset"))
Run Code Online (Sandbox Code Playgroud)

但是,当我尝试生成令牌时,如下所示

var resetToken = await UserManager.GeneratePasswordResetTokenAsync(user.Id);
Run Code Online (Sandbox Code Playgroud)

我得到以下例外.

System.Security.Cryptography.CryptographicException:数据保护操作失败.这可能是由于没有为当前线程的用户上下文加载用户配置文件引起的,这可能是线程模拟时的情况.在System.Security.Cryptography.ProtectedData.Protect(字节[]的UserData,字节[] optionalEntropy,DataProtectionScope范围)在System.Security.Cryptography.DpapiDataProtector.ProviderProtect(字节[]的UserData)在System.Security.Cryptography.DataProtector.Protect (字节[]的UserData)在Microsoft.Owin.Security.DataProtection.DpapiDataProtector.Protect(字节[]的UserData)在Microsoft.AspNet.Identity.Owin.DataProtectorTokenProvider 2.d__0.MoveNext()---来自先前堆栈跟踪结束位置,其中的例外是在Microsoft.AspNet.Identity.UserManager`2.d__e9.MoveNext抛出---在System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(工作任务)在System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务task) ()

security cryptography azure owin

19
推荐指数
4
解决办法
2万
查看次数

appName在DpapiDataProtectionProvider构造函数中有什么影响

在我们IdentityManager班上,我们有以下几行:

protectionProvider = new DpapiDataProtectionProvider("OurProduct");
Run Code Online (Sandbox Code Playgroud)

最后一个参数的含义是什么,它是否与在IIS上设置站点的方式有任何关联?

背景: 我们已经部署MVC5网站有一个自定义IdentityManager类的验证环境中长时间不麻烦,现在我们正在尝试重置用户密码的时候了以下问题:

System.Security.Cryptography.CryptographicException: The data protection operation was unsuccessful. This may have been caused by not having the user profile loaded for the current thread's user context, which may be the case when the thread is impersonating.
Run Code Online (Sandbox Code Playgroud)

以下线程中描述了一些解决方案: 生成重置密码令牌在Azure网站中不起作用

一切都位于同一台机器上:IIS,Sql Server,Firefox测试浏览器.

不幸的是我没有的概念十足的把握,我想弄清楚的测试环境是如何才能引发这一问题,它以前从未发生过变化?

c# owin asp.net-identity

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

在重置密码时出错

我创建了MVC 4应用程序.在该应用程序中如果用户忘记了密码,我有方法向用户发送电子邮件以重置密码.我正在使用asp.net身份会员资格

我在Web服务器中部署此项目时收到以下错误消息.它完全在我的localhost模式下工作.

错误信息

无法编辑此用户数据保护操作失败.这可能是由于没有为当前线程的用户上下文加载用户配置文件引起的,这可能是线程模拟时的情况.

这是忘记密码的方法

    [AllowAnonymous]
    public ActionResult ForgotPassword()
    {
        return View();
    }            

    [HttpPost]
    [AllowAnonymous]
    [ValidateAntiForgeryToken]
    public async Task<ActionResult> ForgotPassword(ForgotPasswordViewModel model)
    {

        if (model.UserName == null)
        {
            ModelState.AddModelError("", "Please enter the Username");
        }

        if (model.Email == null)
        {
            ModelState.AddModelError("", "Please enter the Email ID");
        }

        if (model.Email == null & model.UserName == null)
        {
            ModelState.AddModelError("", "Please enter the Username and Email ID");
        }

        if(ModelState.IsValid)
        {
            var username = await UserManager.FindByNameAsync(model.UserName);
            var user = await UserManager.FindByEmailAsync(model.Email);



            if (user != null …
Run Code Online (Sandbox Code Playgroud)

c# asp.net forgot-password asp.net-mvc-4 asp.net-identity

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

ASP.NET 身份确认令牌长得可笑 - 有什么办法可以缩短它?

我正在使用此代码生成密码重置链接:

    private async Task<string> GetNewEmailConfirmationLink(ApplicationUser user)
    {
        var code = await this.UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
        var callbackUrl = Url.Action(
           "ConfirmEmail",
           "Account",
           new { userId = user.Id, code = code },
           protocol: Request.Url.Scheme);
        return callbackUrl;
    }
Run Code Online (Sandbox Code Playgroud)

原则上,这段代码工作得很好 - 但生成的链接非常长。虽然安全,但有时需要复制粘贴此链接等,然后它的长度往往会导致错误(忘记元素等)。有没有办法缩短这个?

一个生成的链路为例如: http://example.com:9999/de-DE/Account.aspx/ConfirmEmail?userId=1f4f605a-1be5-4b79-9fb0-139687fe8edc&code=0AjkI5qK917WkZw%2Bz0nXf1uK%2BK9bvYAK6BNEVM2l%2Fc%2BlBYOIiitrQ0gMUrB96CCNYc11hnpNpp2Wg2buC548mAb8l9JwzcwfuOiMAXiwJ%2F3iDH1LlXWgiLW% 2FXxcVqLEs2hIhvmye2%2FJxQZD3RcODyNyGD%2FnWjrJRoFK%2B16FtyrtimfNRL%2F1L9vgrk5HiWENn

asp.net asp.net-identity

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

ASP.NET 身份电子邮件确认令牌无效

我正在使用 Asp.Net 身份。当我想使用电子邮件确认令牌确认新用户时,我系统地遇到无效令牌错误。

这是我的 WebApi 用户控制器:

public class UsersController : ApiController
{
    private MyContext _db;
    private MyUserManager _userManager;
    private MyRoleManager _roleManager;


public UsersController()
{
    _db = new MyContext();
    _userManager = new MyUserManager(new UserStore<MyUser>(_db));
    _roleManager = new MyRoleManager(new RoleStore<IdentityRole>(_db));
}

//New user method
[HttpPost]
public async Task<HttpResponseMessage> Register([FromBody]PostUserModel userModel)

{
//New user code
...

var token = await _userManager.GenerateEmailConfirmationTokenAsync(user.Id);
            var message = new IdentityMessage();
            message.Body = string.Format("Hi {0} !\r\nFollow this link to set your password : \r\nhttps://www.mywebsite.com/admin/users/{1}/reset?token={2}", user.UserName, user.Id, HttpUtility.UrlEncode(token));
            message.Subject …
Run Code Online (Sandbox Code Playgroud)

c# asp.net-web-api asp.net-identity

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