c#mvc User.Identity.Name 为空
使用场景:MVC项目中直接显示用户名
一般情况下view中userName:@User.Identity.Name 一般显示为空,如果没有登陆界面,要显示默认用户名步骤如下:
1.在最外层web.config <appSettings> 中添加节点 <add key="enableSimpleMembership" value="false">
2.选中当前项目 按 F4 将 Anonymous Authentication 改为: Disable 和 Windows Authentication 改为: Enable