[英]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
. 通常,有三个选项可用于启动新项目:
IIS
, IIS Express
和Project
。 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
不支持从IIS
或IIS 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.sys
用Windows Authencation
支持Windows Authentication
。
For resolving your issue, you could modify Program.cs
like below to use Http.sys
with Windows Authentcation
. 为了解决您的问题,您可以修改如下的
Program.cs
以将Http.sys
与Windows 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.