且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何从asp中的静态类获取经过身份验证的用户的用户名。净

更新时间:2023-12-02 09:42:10

除非你真的非常需要,否则不要使用静态。



  object  userID = HttpContext.Current.Session [  UserID 跨度>]; 


please can somebody help with how to get the username of authenticated user in asp.net from my static class so that I can query my database that non membership provider one so dat I can fetch additional information about such user from my database. Thanks

By preference, don't use static unless you really, really have to.


But, if you have to: store the Authenticated user id in the Session as usual, then in your static method use the static context:

object userID = HttpContext.Current.Session["UserID"];