简体   繁体   English

AJAX请求期间ASP.NET Page.User为null

[英]ASP.NET Page.User is null during AJAX request

I'm using the MVC2 framework and one of my views has a bit of conditional logic that gets the Page.User.Identity object and does a comparison with other values to determine what to display. 我正在使用MVC2框架,并且我的一个视图具有一些条件逻辑,该条件逻辑获取Page.User.Identity对象,并与其他值进行比较以确定要显示的内容。

That all works fine on the initial page load, but when I make an AJAX call to get partial page updates (I'm doing this all manually with YUI3, not the .NET AJAX stuff) the Page.User object is always null. 所有这些在初始页面加载时都可以正常工作,但是当我进行AJAX调用以获取部分页面更新时(我正在使用YUI3手动完成所有操作,而不是.NET AJAX东西),Page.User对象始终为null。

Anyone know why the Page context seems to be discarding the User object for asynchronous requests? 有人知道为什么Page上下文似乎为异步请求放弃了User对象吗?

Thanks, 谢谢,

Chris 克里斯

If your request-handling method is a static WebMethod , there won't be a page instance to work with and Page itself will be null (that is, you won't even be able to resolve Page.User ). 如果您的请求处理方法是静态的WebMethod ,则将没有可以使用的页面实例,而Page本身将为null (也就是说,您甚至无法解析Page.User )。

If that is indeed the problem, use HttpContext.Current.User instead. 如果确实存在问题,请改用HttpContext.Current.User (And be sure to read Why do ASP.NET AJAX page methods have to be static? ) (并且一定要阅读为什么ASP.NET AJAX页面方法必须是静态的?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM