views:

161

answers:

4

Hello, I use Process.Start("firefox.exe", "http://localhost/page.aspx"); And how i can know page fails or no? OR How to know via HttpWebRequest, HttpWebResponse page fails or not?

When i use

HttpWebRequest myReq = (HttpWebRequest)WebRequest.Create("somepage.aspx");
HttpWebResponse loWebResponse = (HttpWebResponse)myReq.GetResponse();
Console.Write("{0},{1}",loWebResponse.StatusCode, loWebResponse.StatusDescription);

how can I return error details?

Not need additional plugins and frameworks. I want to choose this problem only by .net

Any Idea please

+4  A: 

Use Watin to automate firefox instead of Process.Start. Its a browser automation framework that will let you monitor what is happening properly.

http://watin.sourceforge.net/

edit: see also Google Webdriver http://google-opensource.blogspot.com/2009/05/introducing-webdriver.html

mcintyre321
Didn't know about that. Looks worth checking out.
borisCallens
You could also look at selenium (seleniumhq.org) for web automation testing.
Henrik Jepsen
+2  A: 

If you are spawning a child-process, it is quite hard and you'd probably need to use each browser's specific API (it won't be the same between FF and IE, for example).

It doesn't help that in many cases the exe detects an existing instance and forwards the request there (so you can't trust the exit-code, since the page hasn't even been requested in the right exe yet).

Personally, I try to avoid assuming any particular browser for this scenario; just launch the url:

Process.Start("http://somesite.com");

This will use the user's default browser. You have to hope it appears though - you can't (reliably and robustly) check that externally without lots of work.

One other option is to read the data yourself (WebClient.Download*) - but this may have issues with complex cookies, login, user-agent awareness, etc.

Marc Gravell
thanks, may be alternative way, i must use httpRequest.
loviji
+1  A: 

Use HttpWebRequest class or WebClient class to check this. I don't think Process.Start will return something if the URL not exists.

Anuraj
thanks, i think so, know I trying using HttpWebRequest, HttpWebResponse.
loviji
A: 

Don't start the page in this form. Instead, create a local http://localhost:<port>/wrapper.html which loads http://localhost/page.aspx and then either http://localhost:<port>/pass.html or http://localhost:<port>/fail.html. localhost: is a trivial HTTP server interface implemented by your app.

The idea is that Javascript gives you an API inside the browser, which is far more standard than the APIs on the outside of browsers. Since the Javascript on wrapper.html comes from the same server and even port as the subsequent resources, this should satisfy the same-origin policies in current browsers.

MSalters