WPFセルフサービスの搭乗asp.netでの問題についての記録はurlaclを追加しました

asp.net公共サービスのアドレスは、現在のユーザー権限の問題ので、つながるときにサービスアドレスは、プールurlaclエラーに追加されません。
:urlaclは詳細を追加について、私の以前の記事を参照してください(:UnHandledExceptionメッセージを解決するアクセス拒否問題)のasp.net自己ホストとurlacl

何urlaclは、アドレスプールがあり得るん。


            string _ServerLocalUrl = "http://*:22333/";
            bool isExists = false;

            #region 判断存在否

            try
            {
                var psi = new ProcessStartInfo
                {
                    CreateNoWindow = true,
                    FileName = "cmd.exe",
                    UseShellExecute = false,
                    RedirectStandardInput = true,
                    RedirectStandardOutput = true,
                    RedirectStandardError = true,
                    Verb = "RunAs"
                };

                var process = Process.Start(psi);
                process.StandardInput.WriteLine("netsh http show urlacl");
                process.StandardInput.WriteLine("exit");
                process.StandardInput.Flush();

                StreamReader reader = process.StandardOutput;
                string all = reader.ReadToEnd();
                isExists = all.IndexOf(_ServerLocalUrl) >= 0;
                process.WaitForExit();  //等待程序执行完退出进程
                process.Close();
            }
            catch (Exception ex)
            {
                _Logger.Error(ex, "获取asp.net自宿服务urlacl发生异常。");
            }

            #endregion 判断存在否

あなたが存在しない場合はその後、管理者はurlaclが存在しない登録します。


            #region 如果不存在

            if (!isExists)
            {
                var startInfo = new ProcessStartInfo
                {
                    WindowStyle = ProcessWindowStyle.Hidden,
                    FileName = "cmd.exe",
                    Arguments = $"/C netsh http add urlacl url={_ServerLocalUrl} user=Everyone listen=yes",
                    Verb = "runas"
                };

                try
                {
                    _Logger.Trace($"即将以管理员方式注册不存在的urlacl。arguments = {startInfo.Arguments}");
                    var process = Process.Start(startInfo);
                    process.WaitForExit();
                    process.Close();
                    _Logger.Trace($"完成以管理员方式注册不存在的urlacl。");
                }
                catch (Exception ex)
                {
                    _Logger.Error(ex, "以管理员方式注册不存在的urlacl发生了异常。");
                }
            }

            #endregion 如果不存在

おすすめ

転載: www.cnblogs.com/3Tai/p/11753501.html