HttpContext.User中或在查看Page.User? [英] HttpContext.User or Page.User in a View?
问题描述
如果我在Asp.net MVC视图编码,我想获取当前用户,是它更好地使用
If I'm coding in a View in Asp.net MVC and I want to get the current user, is it better to use
Page.User
或
HttpContext.User中
时有区别吗?
推荐答案
Page.User
收益 this.Context.User
这是完全一样的 HttpContext.User中
,所以没有什么区别,都指向内存中的同一个对象。作为一个方面说明,我建议你不要使用其中任一在查看页面,让控制器所需的数据传递到在这种情况下,你有第三个最佳的选择是在<一个视图href=\"http://msdn.microsoft.com/en-us/library/system.web.mvc.controller.user.aspx\">Controller.User属性。
Page.User
returns this.Context.User
which is exactly the same as HttpContext.User
, so it makes no difference, both point to the same object in memory. As a side note, I would recommend you not to use either of these in a View Page, let the controller pass the needed data to the view in which case you have a third choise which is the Controller.User property.
这篇关于HttpContext.User中或在查看Page.User?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!