开发者

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.

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.

Anyone know why the Page context seems to be discarding th开发者_运维技巧e User object for asynchronous requests?

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).

If that is indeed the problem, use HttpContext.Current.User instead. (And be sure to read Why do ASP.NET AJAX page methods have to be static?)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜