Yes, you can use DotNetBrowser in IIS environment using the off-screen mode.
The next sample displays how to create basic ASP.NET controller that uses DotNetBrowser.
public class BrowserController : Controller
{
private Browser dotNetBrowser;
protected override void Initialize(RequestContext requestContext)
{
base.Initialize(requestContext);
//Create off-screen browser instance
dotNetBrowser = BrowserFactory.Create();
//Subscribe to the web page loaded event
dotNetBrowser.DocumentLoadedInFrameEvent += DotNetBrowser_DocumentLoadedInMainFrameEvent;
}
public ActionResult UrlHandle()
{
string url = "google.com"; //Set URL you need to load
dotNetBrowser.LoadURL(url);
return View();
}
private void DotNetBrowser_DocumentLoadedInMainFrameEvent(object sender, FrameLoadEventArgs frameLoadEventArgs)
{
//Get image references from DOM
IEnumerable<string> imageReferences = dotNetBrowser.GetDocument()
.GetElementsByTagName("img")
.Select(element => (element as DOMElement)?.Attributes["src"]);
foreach (string imageReference in imageReferences)
{
//Do whatever you need
Console.WriteLine(imageReference);
}
//Dispose browser instance after all required actions
dotNetBrowser.Dispose();
}
}
You can find useful information related to your goals by the following links:
Resource handling - https://dotnetbrowser.support.teamdev.com/support/solutions/articles/9000110154-handling-resources-loading
Ajax requests handling - how to get ajax request response body using dotnetbrowser?