Q:
The following code works very well locally but when i try on server .the page hang (and redirect to the login page).
XDocument.Load(targetFileName);
XmlReaderSettings settings = new XmlReaderSettings();
settings.CloseInput = true;
settings.ValidationEventHandler += Handler;
settings.ValidationType = ValidationType.Schema;
settings.Schemas.Add(null, System.Web.HttpContext.Current.Server.MapPath("~/importSchema/IntialSchema.xsd"));
settings.ValidationFlags =
XmlSchemaValidationFlags.ReportValidationWarnings |
XmlSchemaValidationFlags.ProcessIdentityConstraints |
XmlSchemaValidationFlags.ProcessInlineSchema |
XmlSchemaValidationFlags.ProcessSchemaLocation;
using (StreamReader str_reader = new StreamReader(targetFileName))
{
using (XmlReader validatingReader = XmlReader.Create(str_reader, settings))
{
try
{
while (validatingReader.Read())
{
}
}
catch (XmlValidationFailedException ex)
{
Common.ErrMappingForInformix.WriteLog(ex.Message);
this.ShowStatus("error","", 1);
validationFailed = true;
}
}
}
if (validationFailed)
{
return;
}
private static void Handler(object sender, ValidationEventArgs e)
{
if (e.Severity == XmlSeverityType.Error || e.Severity == XmlSeverityType.Warning)
{
string message = String.Format("Line: {0}, Position: {1} \"{2}\"",
e.Exception.LineNumber, e.Exception.LinePosition, e.Exception.Message);
throw new XmlValidationFailedException(message, e.Exception);
}
}
[Serializable()]
public class XmlValidationFailedException : System.Exception
{
public XmlValidationFailedException() : base() { }
public XmlValidationFailedException(string message) : base(message) { }
public XmlValidationFailedException(string message, Exception innerException) : base(message, innerException) { }
protected XmlValidationFailedException(System.Runtime.Serialization.SerializationInfo info,
System.Runtime.Serialization.StreamingContext context) { }
}
I try invalid xml file to check what happens .it works okay locally but on the server i wait long time then it redirects to the login page.i check the event viewer of the IIS and my error folder ,nothing is found.
Add logging or tracing to your code. This will help you to track down what is wrong. Obviously, there’s some kind of difference between your server’s setup and your development PC’s, and that is often a file path, permissions or a different configuration of IIS. By using tracing, you can output file paths, variable values etc. to a trace file.
For instance:
See also http://msdn.microsoft.com/en-us/library/bb386420.aspx.
Good luck!