【发布时间】:2014-09-14 07:30:42
【问题描述】:
我目前正在使用 MVC5 和 Identity 开发一个网站。
我有一个页面,当用户连接(使用帐户)时可以访问,但当他没有连接时也可以访问。如果他已连接,我想显示一些信息。
如果他没有连接,我想显示更少的信息,我想邀请他登录。
我不知道如何实现这样的页面。我有这个控制器:
[Authorize]
public class PController : Controller
{
private int UserId;
public ActionResult Index(int userId ) {
UserId = Convert.ToInt32(((ClaimsIdentity) User.Identity).FindFirst("test").Value);
PModel model = new PModel(UserId);
return View(model);
}
}
还有我的模特:
公共类 PModel { 公共 int 用户 ID { 获取;放; }
public PModel(int userId) {
........
}
在这两种情况下,我都想调用Index方法,并根据模型中的连接进行处理:
public PModel(int userId) {
if(userConnected) {
} else {
}
}
我不知道这是否可能。
【问题讨论】:
标签: asp.net asp.net-mvc-5 asp.net-identity