Web API 启动过程

本文关键字:过程 启动 API Web | 更新日期: 2023-09-27 18:30:55

我相信我在从Web API服务运行Selenium PhantomJS驱动程序时遇到权限问题。我尝试通过各种管理员帐户模拟该服务,但仍然遇到相同的错误。如何确定哪个配置文件引发错误? 我通过打印过程收到此错误。StandardOutput.ReadToEnd()

System.Configuration.ConfigurationErrorsException: Configuration system failed to  initialize
  ---> System.Configuration.ConfigurationErrorsException: An error occurred loading a configuration file: Access is denied.
  ---> System.Security.SecurityException: Access is denied.
   at System.Security.Principal.WindowsIdentity.SafeImpersonate(SafeTokenHandle userToken, WindowsIdentity wi, StackCrawlMark& stackMark)
   at System.Security.Principal.WindowsIdentity.SafeRevertToSelf(StackCrawlMark& stackMark)
   at System.Security.Principal.WindowsIdentity.Impersonate(IntPtr userToken)
   at System.Configuration.ClientConfigurationHost.Impersonate()

Web API 启动过程

这很奇怪,因为 Web 驱动程序不需要您动态更改配置文件。我想你正在尝试自己做所有事情:不要重新发明轮子,因为所有这些事情都已经由硒支持类完成。

为了在Web Api中试用WebDriver:

  • 创建/添加 Web API 项目
  • 添加对 Nuget 包 Selenium Web 驱动程序支持类的引用
  • 将 Web 驱动程序代码添加到操作中

获得 https://stackoverflow.com/头衔的一个非常基本的方法可能是:

using OpenQA.Selenium;
using OpenQA.Selenium.PhantomJS;
...
public string Get()
{
    // c:'phantomjs contains phantomjs.exe
    // if blank, Web Driver will download the latest version
    IWebDriver driver = new PhantomJSDriver(@"c:'phantomjs");
    driver.Navigate().GoToUrl("https://stackoverflow.com/");
    string title = driver.Title;
    driver.Quit();
    return title;
}
  • 就这样!

根据您的主机,支持类在尝试自行启动 phantomjs 时可能会遇到一些问题;只需将应用程序池标识更改为高级用户即可。