Add a flag to set current directory in ANCM InProc (#4369)
This commit is contained in:
parent
50ea144c57
commit
24e17eadca
|
|
@ -23,6 +23,7 @@
|
||||||
#define CS_ASPNETCORE_HOSTING_MODEL_INPROCESS L"inprocess"
|
#define CS_ASPNETCORE_HOSTING_MODEL_INPROCESS L"inprocess"
|
||||||
#define CS_ASPNETCORE_HOSTING_MODEL L"hostingModel"
|
#define CS_ASPNETCORE_HOSTING_MODEL L"hostingModel"
|
||||||
#define CS_ASPNETCORE_HANDLER_SETTINGS L"handlerSettings"
|
#define CS_ASPNETCORE_HANDLER_SETTINGS L"handlerSettings"
|
||||||
|
#define CS_ASPNETCORE_HANDLER_SET_CURRENT_DIRECTORY L"setCurrentDirectory"
|
||||||
#define CS_ASPNETCORE_DISABLE_START_UP_ERROR_PAGE L"disableStartUpErrorPage"
|
#define CS_ASPNETCORE_DISABLE_START_UP_ERROR_PAGE L"disableStartUpErrorPage"
|
||||||
#define CS_ENABLED L"enabled"
|
#define CS_ENABLED L"enabled"
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -60,3 +60,52 @@ Environment::GetEnvironmentVariableValue(const std::wstring & str)
|
||||||
|
|
||||||
return expandedStr;
|
return expandedStr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::wstring Environment::GetCurrentDirectoryValue()
|
||||||
|
{
|
||||||
|
DWORD requestedSize = GetCurrentDirectory(0, nullptr);
|
||||||
|
if (requestedSize == 0)
|
||||||
|
{
|
||||||
|
throw std::system_error(GetLastError(), std::system_category(), "GetCurrentDirectory");
|
||||||
|
}
|
||||||
|
|
||||||
|
std::wstring expandedStr;
|
||||||
|
do
|
||||||
|
{
|
||||||
|
expandedStr.resize(requestedSize);
|
||||||
|
requestedSize = GetCurrentDirectory(requestedSize, expandedStr.data());
|
||||||
|
if (requestedSize == 0)
|
||||||
|
{
|
||||||
|
throw std::system_error(GetLastError(), std::system_category(), "GetCurrentDirectory");
|
||||||
|
}
|
||||||
|
} while (expandedStr.size() != requestedSize + 1);
|
||||||
|
|
||||||
|
expandedStr.resize(requestedSize);
|
||||||
|
|
||||||
|
return expandedStr;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::wstring Environment::GetDllDirectoryValue()
|
||||||
|
{
|
||||||
|
DWORD requestedSize = GetDllDirectory(0, nullptr);
|
||||||
|
if (requestedSize == 0)
|
||||||
|
{
|
||||||
|
throw std::system_error(GetLastError(), std::system_category(), "GetDllDirectory");
|
||||||
|
}
|
||||||
|
|
||||||
|
std::wstring expandedStr;
|
||||||
|
do
|
||||||
|
{
|
||||||
|
expandedStr.resize(requestedSize);
|
||||||
|
requestedSize = GetDllDirectory(requestedSize, expandedStr.data());
|
||||||
|
// 0 might be returned if GetDllDirectory is empty
|
||||||
|
if (requestedSize == 0 && GetLastError() != 0)
|
||||||
|
{
|
||||||
|
throw std::system_error(GetLastError(), std::system_category(), "GetDllDirectory");
|
||||||
|
}
|
||||||
|
} while (expandedStr.size() != requestedSize + 1);
|
||||||
|
|
||||||
|
expandedStr.resize(requestedSize);
|
||||||
|
|
||||||
|
return expandedStr;
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -16,5 +16,9 @@ public:
|
||||||
std::wstring ExpandEnvironmentVariables(const std::wstring & str);
|
std::wstring ExpandEnvironmentVariables(const std::wstring & str);
|
||||||
static
|
static
|
||||||
std::optional<std::wstring> GetEnvironmentVariableValue(const std::wstring & str);
|
std::optional<std::wstring> GetEnvironmentVariableValue(const std::wstring & str);
|
||||||
|
static
|
||||||
|
std::wstring GetCurrentDirectoryValue();
|
||||||
|
static
|
||||||
|
std::wstring GetDllDirectoryValue();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -53,6 +53,10 @@ InProcessOptions::InProcessOptions(const ConfigurationSource &configurationSourc
|
||||||
m_struStdoutLogFile = aspNetCoreSection->GetRequiredString(CS_ASPNETCORE_STDOUT_LOG_FILE);
|
m_struStdoutLogFile = aspNetCoreSection->GetRequiredString(CS_ASPNETCORE_STDOUT_LOG_FILE);
|
||||||
m_fDisableStartUpErrorPage = aspNetCoreSection->GetRequiredBool(CS_ASPNETCORE_DISABLE_START_UP_ERROR_PAGE);
|
m_fDisableStartUpErrorPage = aspNetCoreSection->GetRequiredBool(CS_ASPNETCORE_DISABLE_START_UP_ERROR_PAGE);
|
||||||
m_environmentVariables = aspNetCoreSection->GetKeyValuePairs(CS_ASPNETCORE_ENVIRONMENT_VARIABLES);
|
m_environmentVariables = aspNetCoreSection->GetKeyValuePairs(CS_ASPNETCORE_ENVIRONMENT_VARIABLES);
|
||||||
|
|
||||||
|
const auto handlerSettings = aspNetCoreSection->GetKeyValuePairs(CS_ASPNETCORE_HANDLER_SETTINGS);
|
||||||
|
m_fSetCurrentDirectory = equals_ignore_case(find_element(handlerSettings, CS_ASPNETCORE_HANDLER_SET_CURRENT_DIRECTORY).value_or(L"false"), L"true");
|
||||||
|
|
||||||
m_dwStartupTimeLimitInMS = aspNetCoreSection->GetRequiredLong(CS_ASPNETCORE_PROCESS_STARTUP_TIME_LIMIT) * 1000;
|
m_dwStartupTimeLimitInMS = aspNetCoreSection->GetRequiredLong(CS_ASPNETCORE_PROCESS_STARTUP_TIME_LIMIT) * 1000;
|
||||||
m_dwShutdownTimeLimitInMS = aspNetCoreSection->GetRequiredLong(CS_ASPNETCORE_PROCESS_SHUTDOWN_TIME_LIMIT) * 1000;
|
m_dwShutdownTimeLimitInMS = aspNetCoreSection->GetRequiredLong(CS_ASPNETCORE_PROCESS_SHUTDOWN_TIME_LIMIT) * 1000;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -40,6 +40,12 @@ public:
|
||||||
return m_fDisableStartUpErrorPage;
|
return m_fDisableStartUpErrorPage;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
QuerySetCurrentDirectory() const
|
||||||
|
{
|
||||||
|
return m_fSetCurrentDirectory;
|
||||||
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
QueryWindowsAuthEnabled() const
|
QueryWindowsAuthEnabled() const
|
||||||
{
|
{
|
||||||
|
|
@ -87,7 +93,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
InProcessOptions(const ConfigurationSource &configurationSource);
|
InProcessOptions(const ConfigurationSource &configurationSource);
|
||||||
|
|
||||||
static
|
static
|
||||||
HRESULT InProcessOptions::Create(
|
HRESULT InProcessOptions::Create(
|
||||||
IHttpServer& pServer,
|
IHttpServer& pServer,
|
||||||
|
|
@ -100,6 +106,7 @@ private:
|
||||||
std::wstring m_struStdoutLogFile;
|
std::wstring m_struStdoutLogFile;
|
||||||
bool m_fStdoutLogEnabled;
|
bool m_fStdoutLogEnabled;
|
||||||
bool m_fDisableStartUpErrorPage;
|
bool m_fDisableStartUpErrorPage;
|
||||||
|
bool m_fSetCurrentDirectory;
|
||||||
bool m_fWindowsAuthEnabled;
|
bool m_fWindowsAuthEnabled;
|
||||||
bool m_fBasicAuthEnabled;
|
bool m_fBasicAuthEnabled;
|
||||||
bool m_fAnonymousAuthEnabled;
|
bool m_fAnonymousAuthEnabled;
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,7 @@
|
||||||
#include "resources.h"
|
#include "resources.h"
|
||||||
#include "EventLog.h"
|
#include "EventLog.h"
|
||||||
#include "ModuleHelpers.h"
|
#include "ModuleHelpers.h"
|
||||||
|
#include "Environment.h"
|
||||||
|
|
||||||
IN_PROCESS_APPLICATION* IN_PROCESS_APPLICATION::s_Application = NULL;
|
IN_PROCESS_APPLICATION* IN_PROCESS_APPLICATION::s_Application = NULL;
|
||||||
|
|
||||||
|
|
@ -218,6 +219,25 @@ IN_PROCESS_APPLICATION::ExecuteApplication()
|
||||||
// set the callbacks
|
// set the callbacks
|
||||||
s_Application = this;
|
s_Application = this;
|
||||||
|
|
||||||
|
if (m_pConfig->QuerySetCurrentDirectory())
|
||||||
|
{
|
||||||
|
auto dllDirectory = Environment::GetDllDirectoryValue();
|
||||||
|
auto currentDirectory = Environment::GetCurrentDirectoryValue();
|
||||||
|
|
||||||
|
LOG_INFOF(L"Initial Dll directory: '%s', current directory: '%s'", dllDirectory.c_str(), currentDirectory.c_str());
|
||||||
|
|
||||||
|
// If DllDirectory wasn't set change it to previous current directory value
|
||||||
|
if (dllDirectory.empty())
|
||||||
|
{
|
||||||
|
LOG_LAST_ERROR_IF(!SetDllDirectory(currentDirectory.c_str()));
|
||||||
|
LOG_INFOF(L"Setting dll directory to %s", currentDirectory.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
LOG_LAST_ERROR_IF(!SetCurrentDirectory(this->QueryApplicationPhysicalPath().c_str()));
|
||||||
|
|
||||||
|
LOG_INFOF(L"Setting current directory to %s", this->QueryApplicationPhysicalPath().c_str());
|
||||||
|
}
|
||||||
|
|
||||||
//Start CLR thread
|
//Start CLR thread
|
||||||
m_clrThread = std::thread(ClrThreadEntryPoint, context);
|
m_clrThread = std::thread(ClrThreadEntryPoint, context);
|
||||||
|
|
||||||
|
|
@ -405,6 +425,7 @@ HRESULT
|
||||||
IN_PROCESS_APPLICATION::SetEnvironmentVariablesOnWorkerProcess()
|
IN_PROCESS_APPLICATION::SetEnvironmentVariablesOnWorkerProcess()
|
||||||
{
|
{
|
||||||
auto variables = m_pConfig->QueryEnvironmentVariables();
|
auto variables = m_pConfig->QueryEnvironmentVariables();
|
||||||
|
|
||||||
auto inputTable = std::unique_ptr<ENVIRONMENT_VAR_HASH, ENVIRONMENT_VAR_HASH_DELETER>(new ENVIRONMENT_VAR_HASH());
|
auto inputTable = std::unique_ptr<ENVIRONMENT_VAR_HASH, ENVIRONMENT_VAR_HASH_DELETER>(new ENVIRONMENT_VAR_HASH());
|
||||||
RETURN_IF_FAILED(inputTable->Initialize(37 /*prime*/));
|
RETURN_IF_FAILED(inputTable->Initialize(37 /*prime*/));
|
||||||
// Copy environment variables to old style hash table
|
// Copy environment variables to old style hash table
|
||||||
|
|
@ -422,6 +443,7 @@ IN_PROCESS_APPLICATION::SetEnvironmentVariablesOnWorkerProcess()
|
||||||
m_pConfig->QueryWindowsAuthEnabled(),
|
m_pConfig->QueryWindowsAuthEnabled(),
|
||||||
m_pConfig->QueryBasicAuthEnabled(),
|
m_pConfig->QueryBasicAuthEnabled(),
|
||||||
m_pConfig->QueryAnonymousAuthEnabled(),
|
m_pConfig->QueryAnonymousAuthEnabled(),
|
||||||
|
QueryApplicationPhysicalPath().c_str(),
|
||||||
&pHashTable));
|
&pHashTable));
|
||||||
|
|
||||||
table.reset(pHashTable);
|
table.reset(pHashTable);
|
||||||
|
|
|
||||||
|
|
@ -785,6 +785,7 @@ SERVER_PROCESS::StartProcess(
|
||||||
m_fWindowsAuthEnabled,
|
m_fWindowsAuthEnabled,
|
||||||
m_fBasicAuthEnabled,
|
m_fBasicAuthEnabled,
|
||||||
m_fAnonymousAuthEnabled,
|
m_fAnonymousAuthEnabled,
|
||||||
|
m_struAppFullPath.QueryStr(),
|
||||||
&pHashTable)))
|
&pHashTable)))
|
||||||
{
|
{
|
||||||
pStrStage = L"InitEnvironmentVariablesTable";
|
pStrStage = L"InitEnvironmentVariablesTable";
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@
|
||||||
#define HOSTING_STARTUP_ASSEMBLIES_VALUE L"Microsoft.AspNetCore.Server.IISIntegration"
|
#define HOSTING_STARTUP_ASSEMBLIES_VALUE L"Microsoft.AspNetCore.Server.IISIntegration"
|
||||||
#define ASPNETCORE_IIS_AUTH_ENV_STR L"ASPNETCORE_IIS_HTTPAUTH="
|
#define ASPNETCORE_IIS_AUTH_ENV_STR L"ASPNETCORE_IIS_HTTPAUTH="
|
||||||
#define ASPNETCORE_IIS_WEBSOCKETS_SUPPORTED_ENV_STR L"ASPNETCORE_IIS_WEBSOCKETS_SUPPORTED="
|
#define ASPNETCORE_IIS_WEBSOCKETS_SUPPORTED_ENV_STR L"ASPNETCORE_IIS_WEBSOCKETS_SUPPORTED="
|
||||||
|
#define ASPNETCORE_IIS_PHYSICAL_PATH_ENV_STR L"ASPNETCORE_IIS_PHYSICAL_PATH="
|
||||||
#define ASPNETCORE_IIS_AUTH_WINDOWS L"windows;"
|
#define ASPNETCORE_IIS_AUTH_WINDOWS L"windows;"
|
||||||
#define ASPNETCORE_IIS_AUTH_BASIC L"basic;"
|
#define ASPNETCORE_IIS_AUTH_BASIC L"basic;"
|
||||||
#define ASPNETCORE_IIS_AUTH_ANONYMOUS L"anonymous;"
|
#define ASPNETCORE_IIS_AUTH_ANONYMOUS L"anonymous;"
|
||||||
|
|
|
||||||
|
|
@ -191,6 +191,7 @@ public:
|
||||||
_In_ BOOL fWindowsAuthEnabled,
|
_In_ BOOL fWindowsAuthEnabled,
|
||||||
_In_ BOOL fBasicAuthEnabled,
|
_In_ BOOL fBasicAuthEnabled,
|
||||||
_In_ BOOL fAnonymousAuthEnabled,
|
_In_ BOOL fAnonymousAuthEnabled,
|
||||||
|
_In_ PCWSTR pApplicationPhysicalPath,
|
||||||
_Out_ ENVIRONMENT_VAR_HASH** ppEnvironmentVarTable
|
_Out_ ENVIRONMENT_VAR_HASH** ppEnvironmentVarTable
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
|
|
@ -201,6 +202,7 @@ public:
|
||||||
STACK_STRU(strStartupAssemblyEnv, 1024);
|
STACK_STRU(strStartupAssemblyEnv, 1024);
|
||||||
ENVIRONMENT_VAR_ENTRY* pHostingEntry = NULL;
|
ENVIRONMENT_VAR_ENTRY* pHostingEntry = NULL;
|
||||||
ENVIRONMENT_VAR_ENTRY* pIISAuthEntry = NULL;
|
ENVIRONMENT_VAR_ENTRY* pIISAuthEntry = NULL;
|
||||||
|
ENVIRONMENT_VAR_ENTRY* pIISPathEntry = NULL;
|
||||||
ENVIRONMENT_VAR_HASH* pEnvironmentVarTable = NULL;
|
ENVIRONMENT_VAR_HASH* pEnvironmentVarTable = NULL;
|
||||||
|
|
||||||
pEnvironmentVarTable = new ENVIRONMENT_VAR_HASH();
|
pEnvironmentVarTable = new ENVIRONMENT_VAR_HASH();
|
||||||
|
|
@ -213,7 +215,7 @@ public:
|
||||||
goto Finished;
|
goto Finished;
|
||||||
}
|
}
|
||||||
|
|
||||||
// copy the envirable hash table (from configuration) to a temp one as we may need to remove elements
|
// copy the envirable hash table (from configuration) to a temp one as we may need to remove elements
|
||||||
pInEnvironmentVarTable->Apply(ENVIRONMENT_VAR_HELPERS::CopyToTable, pEnvironmentVarTable);
|
pInEnvironmentVarTable->Apply(ENVIRONMENT_VAR_HELPERS::CopyToTable, pEnvironmentVarTable);
|
||||||
if (pEnvironmentVarTable->Count() != pInEnvironmentVarTable->Count())
|
if (pEnvironmentVarTable->Count() != pInEnvironmentVarTable->Count())
|
||||||
{
|
{
|
||||||
|
|
@ -222,6 +224,22 @@ public:
|
||||||
goto Finished;
|
goto Finished;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pEnvironmentVarTable->FindKey((PWSTR)ASPNETCORE_IIS_PHYSICAL_PATH_ENV_STR, &pIISPathEntry);
|
||||||
|
if (pIISPathEntry != NULL)
|
||||||
|
{
|
||||||
|
// user defined ASPNETCORE_IIS_PHYSICAL_PATH in configuration, wipe it off
|
||||||
|
pIISPathEntry->Dereference();
|
||||||
|
pEnvironmentVarTable->DeleteKey((PWSTR)ASPNETCORE_IIS_PHYSICAL_PATH_ENV_STR);
|
||||||
|
}
|
||||||
|
|
||||||
|
pIISPathEntry = new ENVIRONMENT_VAR_ENTRY();
|
||||||
|
|
||||||
|
if (FAILED(hr = pIISPathEntry->Initialize(ASPNETCORE_IIS_PHYSICAL_PATH_ENV_STR, pApplicationPhysicalPath)) ||
|
||||||
|
FAILED(hr = pEnvironmentVarTable->InsertRecord(pIISPathEntry)))
|
||||||
|
{
|
||||||
|
goto Finished;
|
||||||
|
}
|
||||||
|
|
||||||
pEnvironmentVarTable->FindKey((PWSTR)ASPNETCORE_IIS_AUTH_ENV_STR, &pIISAuthEntry);
|
pEnvironmentVarTable->FindKey((PWSTR)ASPNETCORE_IIS_AUTH_ENV_STR, &pIISAuthEntry);
|
||||||
if (pIISAuthEntry != NULL)
|
if (pIISAuthEntry != NULL)
|
||||||
{
|
{
|
||||||
|
|
@ -259,7 +277,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compiler is complaining about conversion between PCWSTR and PWSTR here.
|
// Compiler is complaining about conversion between PCWSTR and PWSTR here.
|
||||||
// Explictly casting.
|
// Explictly casting.
|
||||||
pEnvironmentVarTable->FindKey((PWSTR)HOSTING_STARTUP_ASSEMBLIES_NAME, &pHostingEntry);
|
pEnvironmentVarTable->FindKey((PWSTR)HOSTING_STARTUP_ASSEMBLIES_NAME, &pHostingEntry);
|
||||||
if (pHostingEntry != NULL)
|
if (pHostingEntry != NULL)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -20,14 +20,14 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests
|
||||||
}
|
}
|
||||||
|
|
||||||
[ConditionalFact]
|
[ConditionalFact]
|
||||||
[RequiresIIS(IISCapability.ShutdownToken)]
|
[RequiresNewHandler]
|
||||||
public async Task HostingEnvironmentIsCorrect()
|
public async Task HostingEnvironmentIsCorrect()
|
||||||
{
|
{
|
||||||
Assert.Equal(
|
Assert.Equal(_fixture.DeploymentResult.ContentRoot, await _fixture.Client.GetStringAsync("/ContentRootPath"));
|
||||||
$"ContentRootPath {_fixture.DeploymentResult.ContentRoot}" + Environment.NewLine +
|
Assert.Equal(_fixture.DeploymentResult.ContentRoot + "\\wwwroot", await _fixture.Client.GetStringAsync("/WebRootPath"));
|
||||||
$"WebRootPath {_fixture.DeploymentResult.ContentRoot}\\wwwroot" + Environment.NewLine +
|
Assert.Equal(Path.GetDirectoryName(_fixture.DeploymentResult.HostProcess.MainModule.FileName), await _fixture.Client.GetStringAsync("/CurrentDirectory"));
|
||||||
$"CurrentDirectory {Path.GetDirectoryName(_fixture.DeploymentResult.HostProcess.MainModule.FileName)}",
|
Assert.Equal(_fixture.DeploymentResult.ContentRoot + "\\", await _fixture.Client.GetStringAsync("/BaseDirectory"));
|
||||||
await _fixture.Client.GetStringAsync("/HostingEnvironment"));
|
Assert.Equal(_fixture.DeploymentResult.ContentRoot + "\\", await _fixture.Client.GetStringAsync("/ASPNETCORE_IIS_PHYSICAL_PATH"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -449,6 +449,23 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests
|
||||||
return dictionary;
|
return dictionary;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[ConditionalFact]
|
||||||
|
[RequiresNewHandler]
|
||||||
|
public async Task SetCurrentDirectoryHandlerSettingWorks()
|
||||||
|
{
|
||||||
|
var deploymentParameters = _fixture.GetBaseDeploymentParameters(publish: true);
|
||||||
|
deploymentParameters.HandlerSettings["SetCurrentDirectory"] = "true";
|
||||||
|
|
||||||
|
var deploymentResult = await DeployAsync(deploymentParameters);
|
||||||
|
|
||||||
|
Assert.Equal(deploymentResult.ContentRoot, await deploymentResult.HttpClient.GetStringAsync("/ContentRootPath"));
|
||||||
|
Assert.Equal(deploymentResult.ContentRoot + "\\wwwroot", await deploymentResult.HttpClient.GetStringAsync("/WebRootPath"));
|
||||||
|
Assert.Equal(deploymentResult.ContentRoot, await deploymentResult.HttpClient.GetStringAsync("/CurrentDirectory"));
|
||||||
|
Assert.Equal(deploymentResult.ContentRoot + "\\", await deploymentResult.HttpClient.GetStringAsync("/BaseDirectory"));
|
||||||
|
Assert.Equal(deploymentResult.ContentRoot + "\\", await deploymentResult.HttpClient.GetStringAsync("/ASPNETCORE_IIS_PHYSICAL_PATH"));
|
||||||
|
Assert.Equal(Path.GetDirectoryName(deploymentResult.HostProcess.MainModule.FileName), await deploymentResult.HttpClient.GetStringAsync("/DllDirectory"));
|
||||||
|
}
|
||||||
|
|
||||||
private static void MoveApplication(
|
private static void MoveApplication(
|
||||||
IISDeploymentParameters parameters,
|
IISDeploymentParameters parameters,
|
||||||
string subdirectory)
|
string subdirectory)
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.AspNetCore.Server.IIS.FunctionalTests.Utilities;
|
using Microsoft.AspNetCore.Server.IIS.FunctionalTests.Utilities;
|
||||||
|
|
@ -68,11 +69,9 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests
|
||||||
|
|
||||||
Assert.Equal("null", responseText);
|
Assert.Equal("null", responseText);
|
||||||
|
|
||||||
Assert.Equal(
|
Assert.Equal(deploymentResult.ContentRoot, await deploymentResult.HttpClient.GetStringAsync("/ContentRootPath"));
|
||||||
$"ContentRootPath {deploymentResult.ContentRoot}" + Environment.NewLine +
|
Assert.Equal(deploymentResult.ContentRoot + "\\wwwroot", await deploymentResult.HttpClient.GetStringAsync("/WebRootPath"));
|
||||||
$"WebRootPath {deploymentResult.ContentRoot}\\wwwroot" + Environment.NewLine +
|
Assert.Equal(deploymentResult.ContentRoot, await deploymentResult.HttpClient.GetStringAsync("/CurrentDirectory"));
|
||||||
$"CurrentDirectory {deploymentResult.ContentRoot}",
|
|
||||||
await deploymentResult.HttpClient.GetStringAsync("/HostingEnvironment"));
|
|
||||||
|
|
||||||
var expectedDll = variant.AncmVersion == AncmVersion.AspNetCoreModule ? "aspnetcore.dll" : "aspnetcorev2.dll";
|
var expectedDll = variant.AncmVersion == AncmVersion.AspNetCoreModule ? "aspnetcore.dll" : "aspnetcorev2.dll";
|
||||||
Assert.Contains(deploymentResult.HostProcess.Modules.OfType<ProcessModule>(), m=> m.FileName.Contains(expectedDll));
|
Assert.Contains(deploymentResult.HostProcess.Modules.OfType<ProcessModule>(), m=> m.FileName.Contains(expectedDll));
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,8 @@
|
||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
using System.Text;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.AspNetCore.Authentication;
|
using Microsoft.AspNetCore.Authentication;
|
||||||
|
|
@ -21,14 +23,15 @@ namespace TestSite
|
||||||
serviceCollection.AddResponseCompression();
|
serviceCollection.AddResponseCompression();
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task HostingEnvironment(HttpContext ctx)
|
private async Task ContentRootPath(HttpContext ctx) => await ctx.Response.WriteAsync(ctx.RequestServices.GetService<IHostingEnvironment>().ContentRootPath);
|
||||||
{
|
|
||||||
var hostingEnv = ctx.RequestServices.GetService<IHostingEnvironment>();
|
|
||||||
|
|
||||||
await ctx.Response.WriteAsync("ContentRootPath " + hostingEnv.ContentRootPath + Environment.NewLine);
|
private async Task WebRootPath(HttpContext ctx) => await ctx.Response.WriteAsync(ctx.RequestServices.GetService<IHostingEnvironment>().WebRootPath);
|
||||||
await ctx.Response.WriteAsync("WebRootPath " + hostingEnv.WebRootPath + Environment.NewLine);
|
|
||||||
await ctx.Response.WriteAsync("CurrentDirectory " + Environment.CurrentDirectory);
|
private async Task CurrentDirectory(HttpContext ctx) => await ctx.Response.WriteAsync(Environment.CurrentDirectory);
|
||||||
}
|
|
||||||
|
private async Task BaseDirectory(HttpContext ctx) => await ctx.Response.WriteAsync(AppContext.BaseDirectory);
|
||||||
|
|
||||||
|
private async Task ASPNETCORE_IIS_PHYSICAL_PATH(HttpContext ctx) => await ctx.Response.WriteAsync(Environment.GetEnvironmentVariable("ASPNETCORE_IIS_PHYSICAL_PATH"));
|
||||||
|
|
||||||
private async Task ConsoleWrite(HttpContext ctx)
|
private async Task ConsoleWrite(HttpContext ctx)
|
||||||
{
|
{
|
||||||
|
|
@ -113,5 +116,15 @@ namespace TestSite
|
||||||
await context.Response.Body.WriteAsync(new byte[100], 0, 100);
|
await context.Response.Body.WriteAsync(new byte[100], 0, 100);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[DllImport("kernel32.dll")]
|
||||||
|
static extern uint GetDllDirectory(uint nBufferLength, [Out] StringBuilder lpBuffer);
|
||||||
|
|
||||||
|
private async Task DllDirectory(HttpContext context)
|
||||||
|
{
|
||||||
|
var builder = new StringBuilder(1024);
|
||||||
|
GetDllDirectory(1024, builder);
|
||||||
|
await context.Response.WriteAsync(builder.ToString());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue