我想运行一些使用 User.Identity.Name 的代码,
我想在用户首次进入网站时运行该代码。 (可以是每次他们关闭浏览器然后重新打开网站)
我尝试将它放在 global.asax 的 Application_Start 中,但 User.Identity.Name 名称返回 null;
我怎样才能做到这一点?
最佳答案
根据您的描述,您可能希望将代码放在 Session_Start 中,而不是 Application_Start 中。 Session_Start 是您的应用程序首次看到每个用户时触发的事件。
这是 Global.asax 中可用的事件列表:http://msdn.microsoft.com/en-us/library/system.web.httpapplication_events%28v=VS.100%29.aspx
关于c# - 当用户第一次访问网站时使用 User.Identity.Name,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6845820/