How to Block a specific url?

1 Answer 533 Views
FiddlerCore Windows
Ryan
Top achievements
Rank 1
Iron
Ryan asked on 28 Aug 2023, 10:00 PM

Okay, so i'm not sure if this is in the right spot or not but here it goes.

 

I am using Fiddler Core in my C# program. In my program; I have several checkboxes and each checkbox sets utilreplaceinresponse; while this is all good; After the session is complete; I need to have Fiddler Block that same url from reloading unless the program is closed or cache is cleared. How can I achieve this?

1 Answer, 1 is accepted

Sort by
0
Nick Iliev
Telerik team
answered on 29 Aug 2023, 07:41 AM

Hello Ryan,

 

Using the OnBeforeRequest event in FiddlerCore, it is simple to block or redirect requests to a specific address.

if (oSession.urlContains("whatever"))
{
   oS.utilCreateResponseAndBypassServer();
   oS.oResponse.headers.SetStatus(404, "Redirect");
   oS.oResponse["Cache-Control"] = "nocache";
   oS.oResponse["Location"] = "http://newurl/";
   oS.utilSetResponseBody("<html><body>sending request elsewhere</body></html>"); 
   return;
}

Using similar logic, return different status codes (e.g. 401) and create a custom login for UI behavior (for example track the application state and triggered this logic when needed while using app flags or similar depending on the technology stack).

 

 

Regards,
Nick Iliev
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Ryan
Top achievements
Rank 1
Iron
commented on 29 Aug 2023, 02:25 PM

Hello Nick Iliev, 

 

I am not sure if I said it the right way but the way I have my software set up is; let's set checkboxes in a c# program. Each of these checkboxes control a different utilreplaceinresponse session. However, let's say example.com is the hostname that is being used. I need example.com to cache the first time through so that the changes can be done with the utilreplaceinresponse. However, it is possible to view the source code of example.com from another tab. So because of the ability to view it's source code in another tab; I need to block that url after the first time it's been loaded for the initial checkboxes. Or; I need the ability to clear the browsers cache after loading the first time.

 

Personally, I have tried to clear the cache after the session was complete using this code:

    FiddlerApplication.AfterSessionComplete += session => 
    {
        Console.WriteLine($"Finished session: {session.fullUrl}");
    }

The problem is; even after running this code to clear cache; the viewable code in the 2nd tab can still see the changes that occurred. It's as if the cache didn't work. I am at a remote site right now and cannot get to my office to show some of my code.

 

It is possible to clear cache after unchecking the checkboxes and but that was another separate issue where the change is still occurring; even if the checkbox is not checked.

Tags
FiddlerCore Windows
Asked by
Ryan
Top achievements
Rank 1
Iron
Answers by
Nick Iliev
Telerik team
Share this question
or