AdvApi32.LookupPrivilegeValue(null, "SeShutdownPrivilege", out var lpLuid);
using var t = AdvApi32.SafeHTOKEN.FromThread(Kernel32.SafeHTHREAD.Current,
AdvApi32.TokenAccess.TOKEN_ADJUST_PRIVILEGES | AdvApi32.TokenAccess.TOKEN_QUERY);
var ptp = new AdvApi32.TOKEN_PRIVILEGES(luid:lpLuid, AdvApi32.PrivilegeAttributes.SE_PRIVILEGE_ENABLED);
AdvApi32.AdjustTokenPrivileges(t,false,ptp,out var old);
User32.ExitWindowsEx(User32.ExitWindowsFlags.EWX_POWEROFF | User32.ExitWindowsFlags.EWX_FORCE,
SystemShutDownReason.SHTDN_REASON_MAJOR_NONE);
需要在nuget上下载:
Vanara.PInvoke.Kernel32
Vanara.PInvoke.User32
Vanara.PInvoke.Security
本文例举了通过 IIS 配置和 C# 代码实现后端允许跨域配置,并介绍了代码实现相关的配置项。最后简单介绍了一下预检请求 Options。