0

I think I'm not understanding something about how asp or windows services works.

I'm trying to create scheduled reporting on my asp.net project. I have a windows service running on my local machine right now, later it will run on a dedicated server. It is supposed to request an ASP page every couple minutes, and on being requested the web page currently emails me on page_load. Here is the code I use in the windows service to call the web page.

HttpWebRequest request= (HttpWebRequest)WebRequest.Create(address);
request.Method = "GET";
response = request.GetResponse();
reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
result = reader.ReadToEnd();

I know it gets this far, because I've been having the service email me too, at every step. However, the web page does nothing when the service requests the page. If I paste the address of the asp page into my browser then I get an email from the page. The ASP.NET website is running in VS debug mode on my computer. Does the service have to open up a browser first?

If a browser is required for the page to work, is there a way for me to run code in my asp project without opening a browser at regular intervals?

Jake Gaston
  • 211
  • 2
  • 7
  • 19

2 Answers2

1

You (almost) cannot open browser from windows a service, as well as it's just wrong to do this. Can you move your email sending to service?

Trinimon
  • 13,839
  • 9
  • 44
  • 60
evgenyl
  • 7,837
  • 2
  • 27
  • 32
1

you can simply call your webpage with the task scheduler

//Create a new scheduled task to open a browser eg: internet explorer then right
//click properties, in the run window type in with the quotes an example
"C:\Program Files\Internet Explorer\iexplore.exe" "http://www.mywebsite.com/something/myactionpage.chtml" 
//If you want to open the page with another browser, just change the first path

or like that

Best Timer for using in a Windows service

Community
  • 1
  • 1
Joan Caron
  • 1,969
  • 18
  • 21