-1

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?

SajidBp
  • 63
  • 2
  • 14

2 Answers2

0

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
Anil
  • 3,722
  • 2
  • 24
  • 49
  • will this run all code in that page code behind each time when this page hit? – SajidBp Mar 21 '17 at 07:53
  • Yes, it will do a httpget to you page. – Anil Mar 21 '17 at 07:55
  • actually , i dont want to get html etc,i just want to load the page,rest of task is done will be done by code, just code to be executed ,without open it in browser. – SajidBp Mar 21 '17 at 07:56
  • then do only _request.GetResponse(), it will get the page (URL) and response will be discarded. – Anil Mar 21 '17 at 08:02
  • will this not cause time out exception?because web request involve in it? – SajidBp Mar 21 '17 at 08:06
  • 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 project. I am not much clear why we need to execute a web page from console?? – Anil Mar 21 '17 at 08:09
  • in fact ,this is email sending code that is schedule to send one time in a day,all code is in code behind page load method,it does not have ain ui,or i do want to execute this code in background, – SajidBp Mar 21 '17 at 08:14
  • It seems you are doing it in wrong way. There should be common utility say "ScheduleEmail" accessible to web page and scheduler. Its ScheduleEmail's responsibility to check if today's email has not been scheduled then scheduled it. Now can call ScheduleEmail from anywhere, this will schedule one email for a day. – Anil Mar 21 '17 at 08:21
  • will this option work fine in cloud?i want to use this in cloud web job? – SajidBp Mar 21 '17 at 08:31
  • Its SRP http://stackoverflow.com/questions/7542051/learning-single-responsibility-principle-with-c-sharp, valid for all software development ;), email sending should not be responsibility of web page, web page should only be responsible for honor ing UI element events, response rendering etc. – Anil Mar 21 '17 at 08:39
-1

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()
SajidBp
  • 63
  • 2
  • 14