如何显示来自SetAuthCookies的数据 [英] How to display data from SetAuthCookies

查看:85
本文介绍了如何显示来自SetAuthCookies的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法使用 SetAuthCookies 显示记录的用户保存,如何检索?

 使用系统; 
using System.Collections.Generic;
using System.Linq;
使用System.Web;
using System.Web.Mvc;
using System.Web.Security;
using logUser.Models;
using logUser.Functions;

命名空间logUser.Controllers
{
public class LoginController:Controller
{
// GET:Login
public ActionResult Login b $ b {
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);
}
}
}
}

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

解决方案

FormsAuthentication.SetAuthCookie 可以调用

  HttpContext.User .Identity.Name 

  Page.User.Identity.Name 

更多信息。 ..



使用表单身份验证获取当前用户ID(非名称)


I'm having a trouble to display the logged User save by using SetAuthCookies how do I retrieve it? I'm still new to this.

Heres my code :

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");
    }
}
}
}

Note : I already configure the Web.config Thanks.

解决方案

When You create a FormsAuthentication.SetAuthCookie to retrive user name you can call

HttpContext.User.Identity.Name

or

Page.User.Identity.Name

More info...

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

这篇关于如何显示来自SetAuthCookies的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆