I use Wamp Server for the back end and C # for the front end. For Cheeking, I will shut down the server. And run the program. It throws the following error in the output window.
'TaskHost.exe' (CLR C:\windows\system32\coreclr.dll: Silverlight AppDomain): Loaded 'C:\windows\system32\System.Core.ni.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled. An exception of type 'System.Net.WebException' occurred in System.Windows.ni.dll and wasn't handled before a managed/native boundary An exception of type 'System.Net.WebException' occurred in System.Windows.ni.dll and wasn't handled before a managed/native boundary
My goal is to catch this Web exception in the message field. Is it possible.
I already use the try, catch statement to catch this exception. But it does not work.
My code
private void Login_Click(object sender, RoutedEventArgs e) { if (string.IsNullOrWhiteSpace(this.username.Text) || string.IsNullOrWhiteSpace(this.password.Password)) { MessageBox.Show("Please Enter the Username and Password"); this.username.Text = ""; this.password.Password = ""; } else { string url = ob.localhost + "login_validate.php"; Uri uri = new Uri(url, UriKind.Absolute); StringBuilder postData = new StringBuilder(); postData.AppendFormat("{0}={1}", "username", HttpUtility.UrlEncode(this.username.Text));// txtUsername.Text)); postData.AppendFormat("&{0}={1}", "password", HttpUtility.UrlEncode(this.password.Password.ToString())); try { WebClient client = default(WebClient); client = new WebClient(); client.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded"; client.Headers[HttpRequestHeader.ContentLength] = postData.Length.ToString(); client.UploadStringCompleted += client_UploadStringCompleted; //client.UploadProgressChanged += client_UploadProgressChanged; client.UploadStringAsync(uri, "POST", postData.ToString()); } catch (Exception ex) { MessageBox.Show(ex.Data.ToString()); MessageBox.Show(ex.GetBaseException().ToString()); } } prog = new ProgressIndicator(); prog.IsIndeterminate = true; prog.IsVisible = true; prog.Text = "Loading...."; SystemTray.SetProgressIndicator(this, prog); }
Please help me. Thanks in advance.
source share