Windows身份验证:与其他帐户连接

时间:2016-04-07 15:17:58

标签: c# asp.net-mvc windows-authentication

我正在使用asp.net mvc使用Windows身份验证制作Web应用程序。

我想添加与AD中其他帐户连接的可能性,

这是我的代码:

public ActionResult ChangeUser()
        {
            HttpCookie cookie = Request.Cookies["TSWA-Last-User"];

            if (User.Identity.IsAuthenticated == false || cookie == null || StringComparer.OrdinalIgnoreCase.Equals(User.Identity.Name, cookie.Value))
            {
                string name = string.Empty;

                if (Request.IsAuthenticated)
                {
                    name = User.Identity.Name;
                }

                cookie = new HttpCookie("TSWA-Last-User", name);
                Response.Cookies.Set(cookie);

                Response.AppendHeader("Connection", "close");
                Response.StatusCode = 401; // Unauthorized;
                Response.Clear();




                Response.Write("refresh page to try again...");
                Response.End();

                return RedirectToAction("Index");
            }

代码工作正常,它显示我弹出一个输入usernam和密码并且用户被更改

问题是:当我点击取消按钮时(在弹出的窗口中)它会将我重定向到401消息,我想要的是当用户点击取消时他应该被重定向到一些索引动作

0 个答案:

没有答案
相关问题