mirror of https://github.com/abpframework/abp.git
45 changed files with 185 additions and 1 deletions
@ -0,0 +1,63 @@ |
|||
using System; |
|||
|
|||
namespace Microsoft.AspNetCore.InProcess |
|||
{ |
|||
/// <summary>
|
|||
/// https://github.com/aspnet/AspNetCore.Docs/blob/master/aspnetcore/host-and-deploy/aspnet-core-module/samples_snapshot/2.x/CurrentDirectoryHelpers.cs
|
|||
/// TODO: Remove CurrentDirectoryHelpers.cs when upgrade to ASP.NET Core 3.0.
|
|||
/// </summary>
|
|||
public class CurrentDirectoryHelpers |
|||
{ |
|||
internal const string AspNetCoreModuleDll = "aspnetcorev2_inprocess.dll"; |
|||
|
|||
[System.Runtime.InteropServices.DllImport("kernel32.dll")] |
|||
private static extern IntPtr GetModuleHandle(string lpModuleName); |
|||
|
|||
[System.Runtime.InteropServices.DllImport(AspNetCoreModuleDll)] |
|||
private static extern int http_get_application_properties(ref IISConfigurationData iiConfigData); |
|||
|
|||
[System.Runtime.InteropServices.StructLayout(System.Runtime.InteropServices.LayoutKind.Sequential)] |
|||
private struct IISConfigurationData |
|||
{ |
|||
public IntPtr pNativeApplication; |
|||
[System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.BStr)] |
|||
public string pwzFullApplicationPath; |
|||
[System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.BStr)] |
|||
public string pwzVirtualApplicationPath; |
|||
public bool fWindowsAuthEnabled; |
|||
public bool fBasicAuthEnabled; |
|||
public bool fAnonymousAuthEnable; |
|||
} |
|||
|
|||
public static void SetCurrentDirectory() |
|||
{ |
|||
try |
|||
{ |
|||
// Check if physical path was provided by ANCM
|
|||
var sitePhysicalPath = Environment.GetEnvironmentVariable("ASPNETCORE_IIS_PHYSICAL_PATH"); |
|||
if (string.IsNullOrEmpty(sitePhysicalPath)) |
|||
{ |
|||
// Skip if not running ANCM InProcess
|
|||
if (GetModuleHandle(AspNetCoreModuleDll) == IntPtr.Zero) |
|||
{ |
|||
return; |
|||
} |
|||
|
|||
IISConfigurationData configurationData = default(IISConfigurationData); |
|||
if (http_get_application_properties(ref configurationData) != 0) |
|||
{ |
|||
return; |
|||
} |
|||
|
|||
sitePhysicalPath = configurationData.pwzFullApplicationPath; |
|||
} |
|||
|
|||
Environment.CurrentDirectory = sitePhysicalPath; |
|||
} |
|||
catch |
|||
{ |
|||
// ignore
|
|||
} |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue