Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/287.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# Blazor应用服务器Windows身份验证在发布后不工作_C#_Blazor_Windows Authentication - Fatal编程技术网

C# Blazor应用服务器Windows身份验证在发布后不工作

C# Blazor应用服务器Windows身份验证在发布后不工作,c#,blazor,windows-authentication,C#,Blazor,Windows Authentication,我想创建一个测试应用程序,它只需使用Windows身份验证自动授权用户。目的是测试并弄清楚基本的Windows身份验证是如何工作的,以及我可以用它做什么 当我在VisualStudio2019中启动应用程序时,身份验证工作正常。但是当我发布应用程序并在本地启动它时,它就不再工作了。我不再被认证了 我创建了一个新的Blazor应用程序,服务器端使用身份验证方法Windows Authentication,并用以下代码重写了FetchData.razor页面。这是我从 @page”/fetchDat

我想创建一个测试应用程序,它只需使用Windows身份验证自动授权用户。目的是测试并弄清楚基本的Windows身份验证是如何工作的,以及我可以用它做什么

当我在VisualStudio2019中启动应用程序时,身份验证工作正常。但是当我发布应用程序并在本地启动它时,它就不再工作了。我不再被认证了

我创建了一个新的Blazor应用程序,服务器端使用身份验证方法Windows Authentication,并用以下代码重写了FetchData.razor页面。这是我从

@page”/fetchData
@使用System.Security.Claims
@使用Microsoft.AspNetCore.Components.Authorization
@注入AuthenticationStateProvider AuthenticationStateProvider
索赔资料
获取ClaimsPrincipal数据
@_authMessage

@如果(_claims.Count()>0) {
    @foreach(var索赔在_索赔中) {
  • @claim.Type:@claim.Value
  • }
} @_姓氏信息

@代码{ 私有字符串authMessage; 私有字符串(u)消息; private IEnumerable_claims=Enumerable.Empty(); 专用异步任务GetClaimsPrincipalData() { var authState=等待AuthenticationStateProvider.GetAuthenticationStateAync(); var user=authState.user; if(user.Identity.IsAuthenticated) { _authMessage=$“{user.Identity.Name}已通过身份验证。”; _索赔=用户索赔; _姓氏信息= $“姓氏:{user.FindFirst(c=>c.Type==ClaimTypes.姓氏)?.Value}”; } 其他的 { _authMessage=“用户未通过身份验证。”; } } }
当我在本地计算机上的VisualStudio2019上执行此操作时,它工作得非常好。我可以按下按钮,我得到了认证,我的所有索赔也被列出。 然后我清理解决方案,重新构建,然后发布它,没有任何错误

我在本地计算机上启动完全发布的应用程序,按下按钮,它告诉我我没有经过身份验证。我不明白,因为事情已经改变了,这是一个已发布的应用程序

我检查了我的launchSettings->windowsAuthentication是否正确,anonymousAuthentication是否正确

我没有在网上找到任何东西,我希望有人知道问题的原因


感谢您的帮助

当您将应用程序发布到IIS时,请确保在web.config中指定了Windows身份验证。对于IIS,它看起来像:

  <system.webServer>
    <security>
      <authentication>
        <windowsAuthentication enabled="true" />
        <anonymousAuthentication enabled="false" />
      </authentication>
    </security>
  </system.webServer>

您还需要
  <system.webServer>
    <security>
      <authentication>
        <windowsAuthentication enabled="true" />
        <anonymousAuthentication enabled="false" />
      </authentication>
    </security>
  </system.webServer>