简体   繁体   English

HttpContext在带有OmniSharp扩展的Visual Studio Code中的工作方式有所不同

[英]HttpContext works differently in visual studio Code with OmniSharp extension

I installed Visual Studio Code and install C# Extension 我安装了Visual Studio Code并安装了C#Extension

https://marketplace.visualstudio.com/items?itemName=ms-vscode.csharp https://marketplace.visualstudio.com/items?itemName=ms-vscode.csharp

When I open existing Asp.Net Core 2 project I can edit files and run web server with debug option ( Debug > Start Debugging ) 当我打开现有的Asp.Net Core 2项目时,我可以编辑文件并使用调试选项运行Web服务器(“ Debug > Start Debugging

But then I got null exception about HttpContext (debug from visual studio 2017 do not throw this error) 但是然后我得到了关于HttpContext的空异常(Visual Studio 2017的调试不会引发此错误)

@User.Identity.Name.Replace(@"Domain\", string.Empty)

When I change code to 当我将代码更改为

@System.Security.Principal.WindowsIdentity.GetCurrent().Name.ToString();

It works. 有用。 So it seems to me that C# Extension run different web server or with different settings than Visual Studio 2017. I have assumption that issue can be in Windows Authentication setting , but i dont have clue where to setup this ? 因此在我看来,C#Extension运行的Web服务器或使用的设置与Visual Studio 2017不同。我假设问题可能出在Windows身份验证设置中 ,但我不知道在哪里进行设置?

Any idea ? 任何想法 ?

This is related with hosting Asp.Net Core . 这与托管Asp.Net Core In general, there are three options for launching new project, IIS , IIS Express and Project . 通常,有三个选项可用于启动新项目: IISIIS ExpressProject When launching from VS 2017 , you may use IIS Express which supports Windows Authentcation and you could configure it by launchsettings.json . VS 2017启动时,您可以使用支持Windows Authentcation IIS Express ,并且可以通过launchsettings.json对其进行launchsettings.json

But, launching from IIS or IIS Express is not supported in VS Code . 但是, VS Code不支持从IISIIS Express启动。 Then you will lauch .NET Core by Project when using VS Code . 然后,在使用VS Code时,您将按Project选择.NET Core When you use self-hosted by Project , you will need to use Http.sys with Windows Authencation to support Windows Authentication . 当您使用自托管的Project ,您将需要使用Http.sysWindows Authencation支持Windows Authentication

For resolving your issue, you could modify Program.cs like below to use Http.sys with Windows Authentcation . 为了解决您的问题,您可以修改如下的Program.cs以将Http.sysWindows Authentcation一起使用。

public static IWebHost BuildWebHost(string[] args) =>
            WebHost.CreateDefaultBuilder(args)
                .UseStartup<Startup>()
                .UseHttpSys(options => {
                    options.Authentication.Schemes =
                        AuthenticationSchemes.NTLM | AuthenticationSchemes.Negotiate;
                        options.Authentication.AllowAnonymous = false;
                })
                .Build();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何让 Omnisharp 扩展在 Visual Studio Code 中工作 - how do I get the Omnisharp extension to work in Visual Studio Code OmniSharp无法在Visual Studio Code中启动 - OmniSharp failed to start in Visual Studio Code OmniSharp 无法在 Visual Studio Code 中正确加载 - OmniSharp fails to load properly in Visual Studio Code 使用.Net Core SDK 3.0预览错误Visual Studio代码和Omnisharp扩展 - Error Visual Studio Code and Omnisharp Extension with .Net Core SDK 3.0 preview Omnisharp 未正确加载 - Visual Studio Code 和 Unity - Omnisharp not loading properly - Visual Studio Code and Unity 如何确定 Visual Studio Code 的 C#/OmniSharp 扩展提供的格式选项的名称和默认值? - How can I determine the names and default values of the formatting options provided by the C#/OmniSharp extension for Visual Studio Code? OmniSharp错误在Visual Studio Code中使用COMReferences加载项目 - OmniSharp error loading projects with COMReferences in Visual Studio Code 使用.Net6 Windows 10 的 OmniSharp 的 Visual Studio 代码出现错误 - Getting Error on Visual Studio Code for OmniSharp with .Net6 Windows 10 vs代码的omnisharp扩展错误 - Error in omnisharp extension for vs code 使用来自Docker的dotnet为Visual Studio C#扩展(OmniSharp)供电 - Using dotnet from docker to power Visual Studio C# extension (OmniSharp)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM