【发布时间】:2012-02-06 03:48:19
【问题描述】:
问:
以下代码在本地运行良好,但是当我在服务器上尝试时,页面挂起(并重定向到登录页面)。
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) { }
}
我尝试无效的xml 文件来检查发生了什么。它在本地工作正常,但在服务器上我等待很长时间然后它重定向到登录页面。我检查IIS 的事件查看器和我的错误文件夹,什么也没找到。
【问题讨论】:
-
如果您提供 SSCCE (homepage1.nifty.com/algafield/sscce.html) 会更容易提供帮助
标签: c# asp.net exception iis xml-validation