为什么它在本地验证但在服务器上失败

发布于 2024-12-25 11:58:06 字数 3148 浏览 1 评论 0原文

问:

以下代码在本地运行得很好,但是当我在服务器上尝试时,页面挂起(并重定向到登录页面)。

                        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 的事件查看器code> 和我的错误文件夹,什么也没找到。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

何以心动 2025-01-01 11:58:06

将日志记录或跟踪添加到您的代码中。这将帮助您找出问题所在。显然,您的服务器设置和开发 PC 之间存在某种差异,这通常是文件路径、权限或 IIS 配置不同。通过使用跟踪,您可以将文件路径、变量值等输出到跟踪文件。

例如:

Trace.Write("Import schema directory: " + Server.MapPath("~/importSchema"));

settings.Schemas.Add(null, System.Web.HttpContext.Current.Server.MapPath("~/importSchema/IntialSchema.xsd"));

另请参阅 http://msdn.microsoft.com/en-us/库/bb386420.aspx

祝你好运!

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:

Trace.Write("Import schema directory: " + Server.MapPath("~/importSchema"));

settings.Schemas.Add(null, System.Web.HttpContext.Current.Server.MapPath("~/importSchema/IntialSchema.xsd"));

See also http://msdn.microsoft.com/en-us/library/bb386420.aspx.

Good luck!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文