asp.net web api服务器端回到angularjs

时间:2015-01-16 01:11:12

标签: c# asp.net-mvc angularjs asp.net-web-api

我正在开发角度js,.net web api 2,visual studio 2013和c#的网站。

我的网址导航完全由angularjs驱动。

重置密码后,我会通过电子邮件发送一个链接给用户,如下所示:

http://localhost:3458/api/Account/ResetPasswordEmail?userId=xxxxxxxxxxxxxxxx9049a8e3-fb90-400a-b73e-78cadc16ae40&code=BVEssssssssssssssssssswT9FsJ3QncMLaPclhLZVUHpHifX8wmG7f3ZrlxDlwkkmcMNccdXz8jdEuGdHM1FJ4WdBu9Yxu9VG43DxamBrasdfasdfasdfbdasdfvgGrqwJxRoJ%2FSCDkOrbV3RupmUaoTgRmebwb1ymBZwkd891G3q6SW%2F%2FTDwOQ7qrkzkAUYtjcwd%2FTH4jNNCzIYmMXF%2BkMF26mBM4Osgc%2Bi%2BO0So41%2Fpp3yK%2BDvEtNCPA%3D%3D&newPassword=xxxxxxxxxx

用户收到电子邮件并点击链接..

在服务器端,执行以下代码:

    //
    // GET: /Account/ResetPasswordEmail
    // GET api/Account/ResetPasswordEmail
    [Route("ResetPasswordEmail", Name = "ResetPasswordEmail")]
    [AllowAnonymous]
    public HttpResponseMessage GetResetPasswordEmail(string userId, string code, string newPassword)
    {
        string errmsg = string.Empty;

        try
        {
            if (userId == null || code == null)
            {
                errmsg = "Either email address or other necessary parameter is null.";
                throw new Exception(errmsg);
            }
            var result = UserManager.ResetPasswordAsync(userId, code, newPassword); 
            var response = Request.CreateResponse(HttpStatusCode.Moved);
            string fullyQualifiedUrl = Request.RequestUri.GetLeftPart(UriPartial.Authority);
            response.Headers.Location = new Uri(fullyQualifiedUrl);
            return response;
        }
        catch(Exception ex)
        {
            return null;
        }
    }

密码重置成功... 但是...... 我想在网页上提供密码已成功或未成功重置的视觉反馈。换句话说,在这种情况下,我的web api将如何与角度js代码对话以呈现UI。我会使用某种asp.net mvc类型的代码吗?

1 个答案:

答案 0 :(得分:0)

  • 在您的网站项目的控制器文件夹中,需要添加用户将通过电子邮件登陆的操作
  • 然后,如果成功,则在该操作中调用api,然后返回该操作中的成功视图