.net core2.2

GetCurrentDirectory returns the worker directory of the process started by IIS rather than the app's directory (for example, C:\Windows\System32\inetsrv for w3wp.exe).

which means config loader will not be able to find appsettings.* files, or any other files such as custom config files, that depend on a GetCurrentDirectory call. In order to solve it in your Program.cs right after public static void Main(string[] args) { add the following line

Directory.SetCurrentDirectory(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location));

 

https://docs.microsoft.com/en-us/aspnet/core/migration/21-to-22?view=aspnetcore-2.2&tabs=visual-studio#call-configurekestrel-instead-of-usekestrel

 

https://devblogs.microsoft.com/aspnet/asp-net-core-2-2-0-preview2-now-available/

https://www.cnblogs.com/stulzq/p/10069412.html

 var path = Directory.GetCurrentDirectory();

 <aspNetCore processPath="dotnet" arguments=".\MyApp.dll" stdoutLogEnabled="false" stdoutLogFile="\\?\%home%\LogFiles\stdout" hostingModel="InProcess"> <handlerSettings> <handlerSetting name="debugFile" value="aspnetcore-debug.log" /> <handlerSetting name="debugLevel" value="FILE,TRACE" /> </handlerSettings> </aspNetCore>

<aspNetCore processPath="dotnet" arguments=".\MyApp.dll" stdoutLogEnabled="false" stdoutLogFile="\\?\%home%\LogFiles\stdout" hostingModel="InProcess"> <environmentVariables> <environmentVariable name="ASPNETCORE_ENVIRONMENT" value="Development" /> <environmentVariable name="CONFIG_DIR" value="f:\application_config" /> </environmentVariables> </aspNetCore>

 eventvwr.msc

解决方式

主动设置一下当前目录为程序根目录:

System.IO.Directory.SetCurrentDirectory(hostingEnvironment.ContentRootPath);
XML
<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <location path="." inheritInChildApplications="false"> <system.webServer> <handlers> <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" /> </handlers> <aspNetCore processPath="dotnet" arguments=".\MyApp.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="InProcess" /> </system.webServer> </location> </configuration> 

以下 web.config 发布用于独立部署

XML复制
<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <location path="." inheritInChildApplications="false"> <system.webServer> <handlers> <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" /> </handlers> <aspNetCore processPath=".\MyApp.exe" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="InProcess" /> </system.webServer> </location> </configuration>


<PropertyGroup> <AspNetCoreHostingModel>OutOfProcess</AspNetCoreHostingModel> </PropertyGroup>

Directory.SetCurrentDirectory(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location));

Try changing the section in csproj

  <PropertyGroup>
    <TargetFramework>netcoreapp2.2</TargetFramework>
    <AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>
  </PropertyGroup>

to the following ...

 <PropertyGroup>
    <TargetFramework>netcoreapp2.2</TargetFramework>
    <AspNetCoreHostingModel>OutOfProcess</AspNetCoreHostingModel>
    <AspNetCoreModuleName>AspNetCoreModule</AspNetCoreModuleName>
 </PropertyGroup>
 

var rand = new Random(1);
var s = Stopwatch.StartNew();
for (var i = 0; i < Count; i++)
{
var ip = new IPAddress(rand.Next(int.MaxValue));
try
{
reader.City(ip);
}
catch (AddressNotFoundException) { }
}
s.Stop();
Console.WriteLine("{0:N0} queries per second", Count / s.Elapsed.TotalSeconds);

 
RepositoryContext
https://code-maze.com/net-core-web-development-part4/


petapoco
https://blog.csdn.net/weixin_42930928/article/details/89513174


var service = (IFooService)serviceProvider.GetService(typeof(IFooService));
var serviceCollection = new Microsoft.Extensions.DependencyInjection.ServiceCollection();

配置

 https://medium.com/@kritner/net-core-console-application-ioptions-t-configuration-ae74bfafe1c5

 https://stackoverflow.com/questions/38114761/asp-net-core-configuration-for-net-core-console-application

 

string url1 = UriHelper.GetEncodedPathAndQuery(HttpContext.Request);
string baseUrl = string.Format("{0}://{1}{2}", Request.Scheme, Request.Host, Request.PathBase);
//redirect to register page
string url = Microsoft.AspNetCore.Http.Extensions.UriHelper.GetEncodedPathAndQuery(context.HttpContext.Request);
if (url!=null && url.StartsWith("/"))
{
url = url.Substring(1);
}
context.Result = new RedirectToActionResult("login", "account", new { ReturnUrl = url});
public static string AppBaseUrl => $"{Current.Request.Scheme}://{Current.Request.Host}{Current.Request.PathBase}";

var displayUrl = UriHelper.GetDisplayUrl(Request);

 

https://sensibledev.com/how-to-get-the-base-url-in-asp-net/

 

转载于:https://www.cnblogs.com/zwei1121/p/10452282.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值