System.Net.WebRequest reqGoogle = System.Net.WebRequest.Create("http://www.google.com/webmasters/tools/ping?sitemap=" + HttpUtility.UrlEncode("http://www.shree/SiteMap/'" + PortalName + "'/sitemap.xml"));
reqGoogle.GetResponse();
Code work fine when google is not blocked.For some region my administrator block the goole.After blocking google code gives an error. How to check the site first if it is blocked or not.plz help.
like this(?):
try
{
System.Net.WebRequest reqGoogle = System.Net.WebRequest.Create("http://www.google.com/webmasters/tools/ping?sitemap=" + HttpUtility.UrlEncode("http://www.shree/SiteMap/'" + PortalName + "'/sitemap.xml"));
reqGoogle.GetResponse();
}
catch(WebException ex)
{
MessageBox.Show("Google is blocked");
}
Related
i've got a bit of a problem trying to set up a general error page in MVC.
I am handling all app errors in Global.asax.cs with the following code ->
protected void Application_Error(object sender, EventArgs e)
{
//if (Request.Url.ToString().StartsWith("http://localhost:"))
// return;
string msg;
Exception ex = Server.GetLastError().GetBaseException();
StringBuilder sb = new StringBuilder();
sb.AppendLine("Exception Found");
sb.AppendLine("Timestamp: " + System.DateTime.Now.ToString());
sb.AppendLine("Error in: " + Request.Url.ToString());
sb.AppendLine("Browser Version: " + Request.UserAgent.ToString());
sb.AppendLine("User IP: " + Request.UserHostAddress.ToString());
sb.AppendLine("Error Message: " + ex.Message);
sb.AppendLine("Stack Trace: " + ex.StackTrace);
msg = sb.ToString();
Server.ClearError();
Response.Redirect(string.Format("~/Error/Error?w={0}", msg ));
}
My problem is that i'm not getting a redirect. I see the same page URL and a blank page when i'm creating an error.
If i remove "errorMsg" and add a SIMPLE STRING, it works, redirects with the required param. Ex:
string test = "testme";
Response.Redirect(string.Format("~/Error/Error?w={0}", test));
That does redirect me to the error page with param "testme". What am i doing wrong here?
You to need escape all the parameters (UrlEncode). At the moment it is unescaped and has a whole bunch of new lines too.
Before you do that, I suggest you just append "hello world" parameter and re-display that to ensure your redirect page is working
I have a "error.aspx" page which is there to mail me if any exception is caught. When I open the page manually, mysite.com/error.aspx, the page opens fine but when it is redirected by a catch block with the exception.message and exception.stackTrace as querystrings, I get an error "page not found". Are the querystrings directing the browser to open a different url? It works fine when run on localhost, though.
public void send_error(Exception ex)
{
Response.Redirect("error.aspx?time=" + DateTime.Now.ToString() + "&ex=" + ex.Message + "&st=" + ex.StackTrace.Replace("\n", " "), false);
}
If you check this Article, you will see that the max query length of url string is 2048 symbols for Internet explorer. Probably the url is bigger and because of that you have this problem. One solution is to save the desire message in the session as string and after that retrieve it on other pages.
string errorMessage = DateTime.Now.ToString() + " " + ex.Message + " " + ex.StackTrace.Replace("\n", " ");
Session["__ErrMessage"] = errorMessage;
When you are in other pages you can access this string like this:
string errMessage = "";
if(Session["__ErrMessage"] != null)
errMessage = Session["ErrMessage"].ToString();
I'm I'm trying to upload a file to my server via FTP, and it's not working. The Upload complete event is triggered, and there are no exceptions being caught by the try catch block. This should be pretty straightforward right? What am I missing here? I know the web directory is right, because I copied and pasted it right from my browser after navigating to it, and the file that I'm uploading is correct because it makes it past the File.Exists, if statement.
string strWebDirectory = "ftp://sharedhosting.com/mydomain.com/wwwroot/Images/" + txt.Text.Trim();
System.Net.WebClient wc = new System.Net.WebClient();
wc.Credentials = new System.Net.NetworkCredential("usr", "psw");
wc.UploadFileCompleted += (s, ev) => UploadProgressCompleted();
if (File.Exists( strStartUpPath + "Upload\\" + txtFile.Text))
{
try
{
wc.UploadFileAsync(new Uri(strWebDirectory), strStartUpPath + "Upload\\" + txtFile.Text);
}
catch (Exception ex)
{
}
}
Any help is appreciated. Thank you.
Look at the Error property. Probably, there was an error.
You need to await/wait on UploadFileAsync to observe the exception it is throwing.
try
{
await wc.UploadFileAsync(new Uri(strWebDirectory), strStartUpPath + "Upload\\" + txtFile.Text);
}
catch (Exception ex)
{
}
I got this error while I call this method from my aspx.cs.
The security validation for this page is invalid. Click Back in your
Web browser, refresh the page, and try your operation again
//SPUtility.ValidateFormDigest(); // still not working although I added it later //hit the error here **** if I add
using (SPSite site = new SPSite(spServerURL))
{
using (SPWeb oWebsite = site.OpenWeb())
{
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (SPSite elevatedSite = new SPSite(site.ID))
{
using (SPWeb elevatedWeb = elevatedSite.OpenWeb(oWebsite.ID))
{
if (elevatedWeb.GetFile(DocumentLibraryName + "/" + folderName + "/" + fileName).Exists)
{
elevatedSite.AllowUnsafeUpdates = true;
#region hitting error
SPFile file = elevatedWeb.GetFile(spDocumentLibraryName + "/" + folderName + "/" + fileName);
file.SetProperty("APPNO", "Test");
file.Update(); //hit the error *****
#endregion
elevatedSite.AllowUnsafeUpdates = false;
}
}
}
});
}
}
I saw some say that if we need to call
SPUtility.ValidateFormDigest(); //hit the error **
method but as soon as I put this line in my codes , I hit the error in this line.
How should I solve it ?
It's working well after I substitute elevatedSite.AllowUnsafeUpdates with elevatedWeb.AllowUnsafeUpdates !!
Did you put the control
in your master page , to which this page is referring ?
If no then put it there and may be this error will vanish.
Let me know your outcome.
I am creating a file on ftp server. But Before creating file on server I also check that it does not existing already. However, It is working fine most of the system but one of my client has problem. When he run the application, it throws the system.formatexception i-e input string is not in correct format.
I am unable to understand this problem. Can anybody help me?
The following is the code to create file.
public string createFile(string filename1)
{
StreamWriter sw1 = null;
System.Net.FtpWebRequest tmpReq1;
try
{
tmpReq1 = (System.Net.FtpWebRequest)System.Net.FtpWebRequest.Create("ftp://ftp.dunyameri.com/pt/" + filename1);
tmpReq1.Credentials = new System.Net.NetworkCredential("naveed#dunyameri.com", "xxxxx");
FtpWebResponse response = (FtpWebResponse)tmpReq1.GetResponse();
}
catch (WebException ex)
{
FtpWebResponse response2 = (FtpWebResponse)ex.Response;
if (response2.StatusCode == FtpStatusCode.ActionNotTakenFileUnavailable)
{
// I am creating file here
}
else
{
return ex.ToString();
}
}
return "File Created";
}
I haves searched on internet that it might be because of string contain 0 or dots. In this particular system case the file name contain dots and 0. Is it because of this type of file name?
Thanks,
Naveed
It seems that the error does not occur within "createFile(string filename1)". If so, the stack should be similar to this:
...
System.Convert.ToInt32(String value)
e2erta.e2erta1.YourFtpClass.createFile(string filename1) <- I would expect this line!
e2erta.e2erta1..ctor()
My best guess would be that filename1 starts with a / character. You can use the Path.Combine method to handle this case:
var path = Path.Combine("ftp://ftp.dunyameri.com/pt/", filename1);
var tmpReq1 = (System.Net.FtpWebRequest)System.Net.FtpWebRequest.Create(path);
...
Url should be something like "ftp://" + userName + ":" + password + "#" + serverAddress + ":" + serverPort + "/" + file.
Try to add port.
The class FtpWebRequest does not have a Create method seelink http://msdn.microsoft.com/en-us/library/system.net.ftpwebrequest_methods
The example shown on link casts WebRequest.Create to FtpWebRequest this might be the issue