How to hit aspx page from console application - vb.net

I have a situation in which I have a aspx page ,that hit on schedule ,all my logic is written in this page.I want that while this page is hit on schedule time,no console window or page that was hit,will not show up.what I have done to hide console window ,
1.just change it to window application output in application setting.
2.and to start aspx page
Dim url As String = ""
url = ConfigurationManager.AppSettings("www.youtube.com")
Process.Start(url)
But Problem is when that page is hit using this code ,that page open up in browser?

if you any logic written in web page code behind that you need to execute from many places, ideally you should move that to a common library project accessible to all other projects.
I am not much clear why we need to execute a web page from console, still you can use WebRequest and WebResponse classes to get the output of the web page without opening in browser.
Dim _request As WebRequest = WebRequest.Create("www.youtube.com")
_request.GetResponse()
Old Answer
using _response As WebResponse = _request.GetResponse()
Using _reader As New StreamReader(_response.GetResponseStream())
Dim _html As String = _reader.ReadToEnd()
End Using
End Using

here is a simple code to run a page without open it in browser.
Dim url As String = ""
url = ConfigurationManager.AppSettings("url")
Dim client As New WebClient
client.DownloadString(url)
client.Dispose()

Related

how to browse a webpage(Page by Page) using webcontrol in vb.net

Through Windows app i want to login into website using webcontrol automatically and i need to search and browse the web pages .. here is my eg:
In load event
Dim webAddress As String = "http:XXXXXXXx"
' WebControl2.WebView.Url = webAddress
WebControl2.WebView.LoadUrlAndWait(webAddress)
WebControl2.WebView.EvalScript("document.getElementsByName('username')[0].value = 'xxxxxx';")
WebControl2.WebView.EvalScript("document.getElementsByName('password')[0].value = 'yyyyy';")
WebControl2.WebView.EvalScript("document.getElementsByName('username')[0].focus();")
WebControl2.WebView.EvalScript("document.getElementsByName('password')[0].focus();")
WebControl2.WebView.SetFocus()
WebControl2.WebView.EvalScript("document.getElementByInputType('submit')[0].click();")
SendKeys.Send("{TAB}")
SendKeys.Send(ControlChars.Cr)
it works fine but i could't access the page which i have loged in

Proxy change on runtime in Awesomium

I've read bunch of Q&As but none helped me.
I'm using VB.net; added awesomium browser control on the form. I need to be able to change its proxy server on the fly (example: User clicks a button to change proxy IP & port). Would it be possible? If not maybe I could create a dynamic awesomium browser control and than add it to the form (also on button click). But still don't know how to initialize control with the proxy.
If I cannot change it while running that is fine. Can I read proxy from some file and than initialize control with that proxy?
Nevermind - below worked for me:
Dim prefs As WebPreferences = New WebPreferences()
prefs.ProxyConfig = txtProxy.Text
Dim session As WebSession = WebCore.CreateWebSession(prefs)
Dim webcontrol As WebControl = New WebControl()
webcontrol.WebSession = session
Me.panWeb.Controls.Add(webcontrol)
webcontrol.Dock = DockStyle.Fill
webcontrol.Source = New Uri(txtURL.Text)
webcontrol.Visible = True

How to get an image from mshtml.htmlimg to hard disk

Without using API?
I know there are several way.
I am using mshtml library by the way, which is better than webbrowser control. I am effectively automating internet explorer straight.
Basically I prefer a way to take the image straight without having to know the URL of the htmlimg and download it.
I know I can take URL from the image element and downloading it with webclient. The image changes depending on cookies and IP. So that wouldn't do.
I want the exact images displayed by the htmlimg element to be the one stored.
Basically as if someone is taking a local screenshot of what shows up on screen.
There's an old solution for this here:
http://p2p.wrox.com/c/42780-mshtml-how-get-images.html#post169674
These days though you probably want to check out the Html Agility Pack:
http://htmlagilitypack.codeplex.com/
The documentation isn't exactly great however; so this code snippet may help:
HtmlDocument htmlDoc = new HtmlDocument();
htmlDoc.LoadHtml(html);
// You can also load a web page by utilising WebClient and loading in the stream - use one of the htmlDoc.Load() overloads
var body = htmlDoc.DocumentNode.Descendants("body").FirstOrDefault();
foreach (var img in body.Descendants("img"))
{
var fileUrl = img.Attributes["src"].Value;
var localFile = #"c:\localpath\tofile.jpg";
// Download the image using WebClient:
using (WebClient client = new WebClient())
{
client.DownloadFile("fileUrl", localFile);
}
}

Web browser header

Here is my code:
Dim TestHeader As String = "Referer: http://www.testrefferer.com"
If chkRefferer.Checked = True Then
WebBrowser1.Navigate(cmbUrl.Text, False, Nothing, TestHeader)
Else
WebBrowser1.Navigate(cmbUrl.Text)
End If
Whenever I try and browse to a page with the 'TestHeader', IE opens up and goes to the page.... However, if I navigate to the same page without the additional header, it loads up fine in my webbrowser control.
Why would this be?
I have changed the 'False' to "_self" and it now works.

Modify HTML in a Internet Explorer window using external.menuArguments

I've got a VB.NET class that is invoked with a context menu extension in Internet Explorer.
The code has access to the object model of the page, and reading data is not a problem. This is the code of a test function...it changes the status bar text (OK), prints the page HTML (OK), changes the HTML by adding a text and prints again the page HTML (OK, in the second pop-up my added text is in the HTML)
But the Internet Explorer window doesn't show it. Where am I doing wrong?
Public Sub CallingTest(ByRef Source As Object)
Dim D As mshtml.HTMLDocument = Source.document
Source.status = "Working..."
Dim H As String = D.documentElement.innerHTML()
MsgBox(H)
D.documentElement.insertAdjacentText("beforeEnd", "ThisIsATest")
H = D.documentElement.outerHTML()
MsgBox(H)
Source.status = ""
End Sub
The function is called like this from JavaScript:
<script>
var EB = new ActiveXObject("MyObject.MyClass");
EB.CallingTest(external.menuArguments);
</script>
To the best of my understanding, in order to use insertAdjacentText or any of the other editing methods, the document object should be in the design mode.
In design mode you can edit the document freely, and so can the user.
Check this site for more details
I do not think that Alex is right, something else is the matter.
When I tried to do something like that, insertBefore would not work for me, but appendChild worked just fine, so adding an element is possible.
I worked in Javascript, but I don't expect that makes a difference.