保存到WebDAV服务器后,Word 2010报告错误

时间:2011-09-08 06:55:12

标签: c# asp.net-mvc-3 ms-office webdav

我有一个使用Sphoirum webdav服务器构建的自定义WebDAV服务器,它驻留在ASP.NET MVC3应用程序中。这是一个.Net 4.0项目。

文档存储库是一个SharePoint,我们的MVC应用程序是它的前端,并通过WebDAV公开整个事物。请注意,我们的IIS 7.5上没有启用WebDAV发布。

我已经实现了以下HTTP谓词:

  • 获取

  • 锁定
  • 选项
  • PROPFIND

  • 解锁

现在,当我打开word文档时,它首先处于只读模式。获得锁定并进入编辑模式是成功的,但是当我想在文档中保存更改时,我得到以下内容:

  

您的更改已保存,但由于错误而无法上传。

诀窍是文档确实正确保存到存储库,而我们的WebDAV服务器对word的响应是HTTP / 200,但Word仍然抱怨。 我也尝试直接从SharePoint存储库中编辑Word,只是为了确认我的Office没有被破坏 - 一切正常。

以下是从Word保存文档时PUT请求的响应:

HTTP/1.1 200 OK
Date: Tue, 06 Sep 2011 12:25:47 GMT
Server: Microsoft-IIS/6.0
X-Powered-By: ASP.NET
MicrosoftSharePointTeamServices: 12.0.0.6545
Last-Modified: Tue, 06 Sep 2011 12:25:47 GMT
ETag: "{F4A63494-D302-4C9B-9C57-D0CB0937A2B0},9"
ResourceTag: rt:F4A63494-D302-4C9B-9C57-D0CB0937A2B0@00000000009
X-MSDAVEXTLockTimeout: Second-3600
Lock-Token: opaquelocktoken:{F4A63494-D302-4C9B-9C57-D0CB0937A2B0}20110906T122532Z
Expires: Mon, 22 Aug 2011 12:25:47 GMT
Cache-Control: private,max-age=0
Content-Length: 0
Public-Extension: http://schemas.microsoft.com/repl-2
Set-Cookie: WSS_KeepSessionAuthenticated=40689; path=/

对于同一文档,来自我们的WebDAV服务器的回复相同:

HTTP/1.1 200 OK
Cache-Control: private,max-age=0
Content-Length: 0
Expires: Wed, 24 Aug 2011 08:03:28 GMT
Last-Modified: Wed, 07 Sep 2011 08:03:28 GMT
ETag: "{4a4331a8-7df6-43e6-bd5f-bb80765e83a2},1"
Server: Microsoft-IIS/7.5
MS-Author-Via: DAV
ResourceTag: rt:4a4331a8-7df6-43e6-bd5f-bb80765e83a2@00000000001
Lock-Token: opaquelocktoken:{4a4331a8-7df6-43e6-bd5f-bb80765e83a2}20110907T080328Z
X-MSDAVEXTLockTimeout: Second-3600
Public-Extension: http://schemas.microsoft.com/repl-2
MicrosoftSharePointTeamServices: 12.0.0.6545
Set-Cookie: WSS_KeepSessionAuthenticated=40689; path=/
X-Powered-By: ASP.NET
Date: Wed, 07 Sep 2011 08:03:27 GMT

所以我试图模仿SharePoint发布的一些标题,例如 MicrosoftSharePointTeamServices ,但无济于事。

3 个答案:

答案 0 :(得分:3)

顺便说一句,我发现Sphorium webdav中的错误导致了这个问题。该错误出现在方法 DavLockBase_InternalProcessDavRequest()中,错误的代码行是:

string[] _lockTokens = this.RequestLock.GetLockTokens();

应该是:

string[] _lockTokens = this.ResponseLock.GetLockTokens();

在更改之后,在Word 2010中保存文件工作正常。

答案 1 :(得分:1)

如果有人再遇到这个问题,这里有一个基于上述答案构建的修复程序,以及我在使用单词2010时找到的内容。基本上修复涉及替换" DavLockBase_InternalProcessDavRequest&的代码#34;方法(我已经为每个"更正"添加了一些评论。)

作为一个注释(找到一些信息here):word20的webdav实现的行为在客户端是否安装了补丁方面有所不同;因此,在所有情况下都可能不需要进行第3次校正!

希望它有所帮助!

private int DavLockBase_InternalProcessDavRequest(object sender, EventArgs e)
    {
        int _responseCode = (int)DavLockResponseCode.Ok;

        //string[] _lockTokens = this.RequestLock.GetLockTokens();
        //#1 the above line is incorrect. replaced with the following:
        string[] _lockTokens = this.ResponseLock.GetLockTokens();

        //Check to see if a lock refresh was requested
        if (base.HttpApplication.Request.Headers["If"] != null)
        {
            if (_lockTokens.Length == 1)
            {
                //#2 not sure why this should be done (or not), however I've seen this in other people corrections.
                //DavRefreshEventArgs _refreshEventArgs = new DavRefreshEventArgs(_lockTokens[0], this.RequestLock.LockTimeout);
                //OnRefreshLockDavRequest(_refreshEventArgs);
            }

            base.HttpApplication.Response.AppendHeader("Timeout", "Second-" + this.ResponseLock.LockTimeout);
        }
        else
        {
            //New lock request
            StringBuilder _opaquelockTokens = new StringBuilder();
            //#3 finally, added the check below, as most of the times, when using word 2010 there are no lock requests
            if (_lockTokens.Length > 0)
            {
                foreach (string _lockToken in _lockTokens)
                    _opaquelockTokens.Append("<opaquelocktoken:" + _lockToken + ">");

                base.HttpApplication.Response.AppendHeader("Lock-Token", _opaquelockTokens.ToString());
            }
        }

        //Check to see if there were any process errors...
        Enum[] _errorResources = this.ProcessErrorResources;
        if (_errorResources.Length > 0)
        {
            //Append a response node
            XmlDocument _xmlDocument = new XmlDocument();
            XmlNode _responseNode = _xmlDocument.CreateNode(XmlNodeType.Element, _xmlDocument.GetPrefixOfNamespace("DAV:"), "response", "DAV:");

            //Add the HREF
            XmlElement _requestLockHrefElement = _xmlDocument.CreateElement("href", "DAV:");
            _requestLockHrefElement.InnerText = base.RelativeRequestPath;
            _responseNode.AppendChild(_requestLockHrefElement);


            //Add the propstat
            XmlElement _propstatElement = _xmlDocument.CreateElement("propstat", "DAV:");
            XmlElement _propElement = _xmlDocument.CreateElement("prop", "DAV:");
            XmlElement _lockDiscoveryElement = _xmlDocument.CreateElement("lockdiscovery", "DAV:");
            _propElement.AppendChild(_lockDiscoveryElement);
            _propstatElement.AppendChild(_propElement);

            XmlElement _statusElement = _xmlDocument.CreateElement("status", "DAV:");
            _statusElement.InnerText = InternalFunctions.GetEnumHttpResponse(DavLockResponseCode.FailedDependency);
            _propstatElement.AppendChild(_statusElement);

            _responseNode.AppendChild(_propstatElement);

            base.SetResponseXml(InternalFunctions.ProcessErrorRequest(this.ProcessErrors, _responseNode));
            _responseCode = (int)ServerResponseCode.MultiStatus;
        }
        else
        {
            //No issues
            using (Stream _responseStream = new MemoryStream())
            {
                XmlTextWriter _xmlWriter = new XmlTextWriter(_responseStream, new UTF8Encoding(false));

                _xmlWriter.Formatting = Formatting.Indented;
                _xmlWriter.IndentChar = '\t';
                _xmlWriter.Indentation = 1;
                _xmlWriter.WriteStartDocument();

                //Open the prop element section
                _xmlWriter.WriteStartElement("D", "prop", "DAV:");
                _xmlWriter.WriteStartElement("lockdiscovery", "DAV:");
                this.ResponseLock.ActiveLock.WriteTo(_xmlWriter);
                _xmlWriter.WriteEndElement();
                _xmlWriter.WriteEndElement();

                _xmlWriter.WriteEndDocument();
                _xmlWriter.Flush();

                base.SetResponseXml(_responseStream);
                _xmlWriter.Close();
            }
        }

        return _responseCode;
    }

答案 2 :(得分:0)

观察:锁定令牌使用无效语法(Sharepoints也是如此)。也;大多数这些标题不应该被需要(是专有的)或者不适用于PUT响应(例如Lock-Token)。

我建议先尝试使用mod_dav发布到Apache,然后观察HTTP交换。