Quantcast
Channel: SharePoint 2013 - Development and Programming forum
Viewing all articles
Browse latest Browse all 25064

Urgent: How to filter FPRPC response in sharepoint?

$
0
0
We have a project to filter file download from sharepoint. Our method is that we replace HttpResponse.Filter with our filter derived from Stream(see the code below) in PreProcessHttpRequest event of HttpApplication.
It works quite well for GET method and WebDAV command. But a HttpException(description="The Http verb Post used to access Path '/_vti_bin/_vti_aut/author.dll' is not allowed") is threw in SPHttpHandler.BeginProcessRequest() when the Request is "POST /_vti_bin/_vti_auth/author.dll" with "method=get document".(FPRPC)

Does anyone know the reason? Does the HttpResponse.Filter can not be replaced in sharepoint 3.0.

We have also tried using MyHttpHandler derived from IHttpAsyncHandler, and we call SPHttpHandler.BeginProcessRequest() in MyHttpHandler.BeginProcessRequest and passed a callback implemented by ourselves. But we found the FPRPC has been sent out when our callback is called.

Is there any other good method to filter FPRPC response in sharepoint 3.0?

I'll be very appreciated if someone can solve the problem.

Sample code:
public abstract class HttpFilterBase : Stream
    {
        private Stream _baseStream;
        private bool _closed;

        protected Stream BaseStream
        {
            get { return this._baseStream; }
        }

        public override bool CanRead
        {
            get { return false; }
        }

        public override bool CanWrite
        {
            get { return !_closed; }
        }

        public override bool CanSeek
        {
            get { return false; }
        }

        protected bool Closed
        {
            get { return _closed; }
        }

        public override long Length
        {
            get { throw new NotSupportedException(); }
        }

        public override long Position
        {
            get { throw new NotSupportedException(); }
            set { throw new NotSupportedException(); }
        }

        protected HttpFilterBase(Stream _baseStream)
        {
            this._baseStream = _baseStream;
            this._closed = false;
        }

        public override void Write(byte[] buffer, int offset, int count)
        {
            _baseStream.Write(buffer, offset, count);
        }

        public override void Close()
        {
            if (!_closed)
            {
                _closed = true;
                _baseStream.Close();
            }
        }

        public override void Flush()
        {
            _baseStream.Flush();
        }

        public override int Read(byte[] buffer, int offset, int count)
        {
            throw new NotSupportedException();
        }

        public override long Seek(long offset, SeekOrigin origin)
        {
            throw new NotSupportedException();
        }

        public override void SetLength(long value)
        {
            throw new NotSupportedException();
        }
    }

    // This filter changes all characters passed through it to uppercase.
    public class HEResponseFilterStream : HttpFilterBase
    {
        private HttpApplication application;

        public HEResponseFilterStream(Stream sink, Object source)
            : base(sink)
        {
            application = (HttpApplication)source;
        }

        public override void Close()
        {
            base.Close();
        }

        public override void Flush()
        {
            HttpContext context = application.Context;
            HttpRequest Request = context.Request;
            HttpResponse Response = context.Response;
           
            base.Flush();
        }

        // The Write method actually does the filtering.
        public override void Write(byte[] buffer, int offset, int count)
        {
            HttpContext context = application.Context;
            HttpRequest Request = context.Request;
            HttpResponse Response = context.Response;

          {
                base.Write(buffer, offset, count);
                return;
            }
        }       
    }


Viewing all articles
Browse latest Browse all 25064


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>