【问题标题】:How to display data from SetAuthCookies如何显示来自 SetAuthCookies 的数据
【发布时间】:2016-01-26 08:59:43
【问题描述】:

我无法使用SetAuthCookies 显示已登录的用户保存,我该如何检索它?我还是新手。

这是我的代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Security;
using logUser.Models;
using logUser.Functions;

namespace logUser.Controllers
{
public class LoginController : Controller
{
// GET: Login
public ActionResult Login()
{
    return View();
}

[HttpPost]
public ActionResult DoLogin(logUser.Models.UserInfo u)
{
    Employee bal = new Employee();
    if (bal.IsValidUser(u))
    {
        FormsAuthentication.SetAuthCookie(u.UserName, true);
        return RedirectToAction("Index", "Home");
    }
    else
    {
        return View("Login");
    }
}
}
}

注意:我已经配置了 Web.config 谢谢。

【问题讨论】:

    标签: c# cookies


    【解决方案1】:

    当您创建FormsAuthentication.SetAuthCookie 来检索用户名时,您可以调用

    HttpContext.User.Identity.Name
    

    Page.User.Identity.Name
    

    更多信息...

    Getting the current user id (not name) using forms authentication?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-12-03
      • 2021-12-03
      • 2015-07-29
      • 2021-11-25
      相关资源
      最近更新 更多