Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/306.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 为什么在使用Windows Azure Emulator时Windows身份验证失败?_C#_Azure_Windows Authentication_Azure Cloud Services - Fatal编程技术网

C# 为什么在使用Windows Azure Emulator时Windows身份验证失败?

C# 为什么在使用Windows Azure Emulator时Windows身份验证失败?,c#,azure,windows-authentication,azure-cloud-services,C#,Azure,Windows Authentication,Azure Cloud Services,我创建了一个云服务项目,其中包含Web角色中的MVC应用程序,以及工作者角色。在MVC项目中,我使用的是Windows身份验证…并且某些字段是根据被授权的用户进行管理的(没有什么大不了的) 当我在MVC项目中“设置为启动项目”时,我的Windows身份主体表现良好……一切都按预期显示和工作(这很好) 然后,就到了处理和调试工作者角色的时候了。为此,我必须运行windowsazure模拟器,方法是选择云服务项目本身的“设置为启动项目”(然后按F5)。这样做将启动Windows Azure Emul

我创建了一个
云服务
项目,其中包含
Web角色中的
MVC应用程序
,以及
工作者角色
。在MVC项目中,我使用的是
Windows身份验证
…并且某些字段是根据被授权的用户进行管理的(没有什么大不了的)

当我在MVC项目中“设置为启动项目”时,我的
Windows身份主体
表现良好……一切都按预期显示和工作(这很好)

然后,就到了处理和调试
工作者角色的时候了。为此,我必须运行
windowsazure模拟器
,方法是选择
云服务
项目本身的“设置为启动项目”(然后按F5)。这样做将启动
Windows Azure Emulator
中的所有
云服务
角色

但是,当我这样做时,
IsAuthenticated
属性为false…我的所有HTML元素都消失了

问题:
-为什么在本地运行
Windows Azure Emulator
会阻止
Windows身份验证

-如果我需要“设置”模拟器…如何


安全代码部分:
这里没什么特别的

var identity = filterContext.HttpContext.Request.LogonUserIdentity;
if (!identity.IsAuthenticated)
   RedirectToAccessDeniedPage(filterContext);
<authentication mode="Windows" />
<identity impersonate="false" />
WEB配置的部分:
这里没什么特别的

var identity = filterContext.HttpContext.Request.LogonUserIdentity;
if (!identity.IsAuthenticated)
   RedirectToAccessDeniedPage(filterContext);
<authentication mode="Windows" />
<identity impersonate="false" />

将MVC项目设置为启动项目时,实际上是通过IIS在计算机上本地运行该项目。IIS将自动使用您当前的NT凭据作为当前登录的用户,这很有意义

正如Parv Sharma在其评论中暗示的那样,当您将云服务设置为启动项目时,会启动一个单独的VM Emulator,模拟云中会发生什么。尽管VM也在IIS中运行您的应用程序,但它不知道您是谁,因为您尚未登录。而且,由于您的本地NT凭据未存储在该VM中(而且不管怎样,将用户凭据存储在VM中都没有意义),IIS不会将您识别为已登录


因此,您需要实现一种身份验证表单,允许用户对目录存储进行身份验证,这就是Azure目录服务的全部内容。以下是场景的MSDN文档,其中包含示例实现的链接。

这可能是因为Microsoft azure emulator是一个虚拟机,因此您的windows auth无法在那里工作。除非你手动设置