User.Identity.Name在ASP.Net MVC空白 [英] User.Identity.Name blank in ASP.Net MVC

查看:572
本文介绍了User.Identity.Name在ASP.Net MVC空白的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

完全按标题。

只要在我的HomeController我有:

Simply in my HomeController I have:

string Username = User.Identity.Name;

这是为什么值始终为空?

Why is this value always blank?

是不是有什么特别的我在web.config中的地方得到这个值才能通过。我都试过了VS开发Web服务器上,以及在Windows Server 2003 IIS服务器上。

Is there something special I have to place in the web.config to get this value to come through. I've tried on both the VS dev web server as well as on a windows server 2003 IIS server.

这一定是简单的东西,在IIS服务器设置或东西为code是如此简单,似乎是引用此值的正确方法。

It's got to be something simple, a server setting in IIS or something as the code is so simple and seems to be the correct way to reference this value.

THX很多

推荐答案

当然是队友。您需要与该网站进行身份验证。这是用于身份验证的名称。

Sure is mate. You need to authenticate with the website. That's the name used for authentication.

您进行认证,对吧?

这不是一个设置等。

点击登录链接,如果您使用的股票标准的ASP.NET MVC模板(如果我没记错的话)。

Click the LOG IN link, if you're using the stock standard ASP.NET MVC template (if my memory serves me right).

那么,你是后Windows身份验证。 A <罢工> quick 想出了这个帖子谷歌搜索。这是pretty有用(虽然有点老了,但仍然相关)。检查了这一点。

So what you're after is Windows Authentication. A quick google search came up with this post. It's pretty helpful (though a bit old, but still relevant) .. check that out.

更好帖子与MVC code为Windows身份验证。检查出来吧。

Found a better post with MVC code for Windows Authentication. Check that out instead.

配置设置,这一点很重要,就是...

Config setting that is important, is...

...
 <system.web>
  ...
  <authentication mode="Windows"/>
  ...
 </system.web>
 ...

这篇关于User.Identity.Name在ASP.Net MVC空白的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆