简体   繁体   English

Windows 10 - 任务计划程序 - 代理设置/身份验证

[英]Windows 10 - Task Scheduler - Proxy Setting / Authentication

All,全部,

I have a simple C#.Net console application calling a external REST API via a proxy configured in browser.我有一个简单的 C#.Net 控制台应用程序,通过浏览器中配置的代理调用外部 REST API。 The application works fine from Visual Studio / directly run exe manually.该应用程序在 Visual Studio 中运行良好/直接手动运行 exe。 This is a windows 10 desktop这是 windows 10 台式机

When i try to do the same through a windows scheduled task, the program runs only with the option of user logged in. Else when i choose run whether the user is logged in or not under my context - the program fails stating the that the end point is blocked.当我尝试通过 windows 计划任务执行相同操作时,程序仅在用户登录选项下运行。否则,当我选择运行时,无论用户是否在我的上下文中登录 - 程序都无法说明结束点被封锁。 Either it never takes the proxy or the proxy authentication fails.要么它从不使用代理,要么代理身份验证失败。

I tried to set the web proxy credentials in code, proxy settings in app.config nothing to the rescue.我试图在代码中设置 web 代理凭据,app.config 中的代理设置无济于事。

Has anyone faced similar issue?有没有人遇到过类似的问题? Is there a cleaner way to do this?有没有更清洁的方法来做到这一点?

Thanks, Goutham谢谢, 古瑟姆

I had very similar issue, i could create a scheduled task using my account, but not a service account, well when i did the service account would fail to run the scheduled task, it was due to proxy server in our env.我有非常相似的问题,我可以使用我的帐户创建计划任务,但不能使用服务帐户,当我这样做时,服务帐户将无法运行计划任务,这是由于我们环境中的代理服务器。

so i was using this line WebRequest所以我正在使用这一行 WebRequest

 WebProxy proxyObject = new WebProxy("Http://proxy:80");
                WebRequest.DefaultWebProxy = proxyObject;

this for some reason let me schedule the task for my.exe i was developing and not work with a service account.出于某种原因,这让我为我正在开发的 my.exe 安排任务,而不是使用服务帐户。 apparently WebRequest is old and should not be used i found out.显然 WebRequest 很旧,我发现不应该使用它。

so i switch to HttpRequest..所以我切换到HttpRequest ..

WebProxy proxyObject = new WebProxy("Http://proxy:80");
                HttpClient.DefaultProxy = proxyObject;

now i'm able to schedule tasks with no issues with svc account or local account, whatever i want:).现在我可以用 svc 帐户或本地帐户安排任务,无论我想要什么:)。

Have you tried authenticating via Login as a service?您是否尝试过通过登录即服务进行身份验证?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM