0

im using awesomium and vb.net as a client side application for my web application. Can anyone say me how to cancel a request when a url contain a specific key word. for example , if my url contains view , then i need to cancel the request and download the pdf to local machine and view it with client pdf viewer. i had done the second part but i dont know how to cancel the the request.

using vb.net native webcontrol i have navigating event . but what it the event equivalent to this in awesomium

below is the code im using

Public Class ResourceInterceptor  Implements IResourceInterceptor
Public Function OnFilterNavigation(ByVal request As NavigationRequest) As Boolean Implements IResourceInterceptor.OnFilterNavigation
    If request.Url.ToString.Contains("ViewPdf") Then
        Path = ExtractPath(request.Url.ToString)
        openpdf(Path)
        Return False ' Cancel the request. 
    Else
        System.Diagnostics.Process.Start(request.Url.ToString)
        Return True
    End If
End Function

Public Function OnRequest(ByVal request As ResourceRequest) As ResourceResponse Implements IResourceInterceptor.OnRequest
    Return Nothing
End Function

End Class

Can any one say how to cancel a request when a url contain a specified text

Yuvaraj
  • 166
  • 1
  • 2
  • 11
  • i made a small mistake. to block any incoming request you have to return true and not false. now it is working perfectly – Yuvaraj Feb 07 '14 at 14:52

1 Answers1

0

Implement the Awesomium.Core.IResourceInterceptor interface and attach it to your webcore session with WebCore.ResourceInterceptor = new ResourceInterceptor();

Here is a simple ResourceInterceptor in C#.

using System;
using System.IO;
using System.Reflection;
using Awesomium.Core;

namespace MyApp
{
    public class ResourceInterceptor : IResourceInterceptor
    {
        /// <summary>
        ///     Not used.
        /// </summary>
        public virtual ResourceResponse OnRequest(ResourceRequest request)
        {
             return null;
        }

        /// <summary>
        ///     Optionally blocks any web browser requests by returning true when the URL contains "/view/".
        /// </summary>
        public virtual bool OnFilterNavigation(NavigationRequest request)
        {
            return String.Contains(request.Url.AbsolutePath, "/ViewPdf/", StringComparison.InvariantCultureIgnoreCase);
        }
    }
}
Steve Jansen
  • 9,398
  • 2
  • 29
  • 34
  • Thanks for your time steve jansen. – Yuvaraj Feb 04 '14 at 06:49
  • @Yuvaraj if this solved your problem, can you please mark my answer as the accepted answer? – Steve Jansen Feb 04 '14 at 14:28
  • Steve Jansen , it is not working for me . i edited my Question , please say me where i made wrong . – Yuvaraj Feb 07 '14 at 08:55
  • I was testing for "/view/" originally. Updated to match against "/ViewPdf/". Try this and set a breakpoint at the `OnFilterNavigation` method. This should be hit many times as you load a page, returning true only for URLs containing "/ViewPdf/". If not, you forgot to attach it to your session with `WebCore.ResourceInterceptor = new ResourceInterceptor();` – Steve Jansen Feb 07 '14 at 15:10
  • Steve thanks for your time. its now working. thanks for your help and time to put me on the right direction – Yuvaraj Feb 07 '14 at 15:31