# Securing the Signature Endpoint with Custom ActionFilterAttributes

> The HttpPost endpoint to which the signed document is forwarded can be in the same application or a completely different application. This tutorial will show you how to secure this endpoint through the use of custom filter attributes in ASP.NET Core.

- **Author:** Bjoern Meyer
- **Published:** 2023-07-25
- **Modified:** 2026-07-17
- **Description:** The HttpPost endpoint to which the signed document is forwarded can be in the same application or a completely different application. This tutorial will show you how to secure this endpoint through the use of custom filter attributes in ASP.NET Core.
- **3 min read** (401 words)
- **Tags:**
  - ASP.NET
  - ASP.NET Core
  - Electronic Signatures
  - Document Viewer
- **Web URL:** https://www.textcontrol.com/blog/2023/07/25/securing-the-signature-endpoint-with-custom-actionfilterattributes/
- **LLMs URL:** https://www.textcontrol.com/blog/2023/07/25/securing-the-signature-endpoint-with-custom-actionfilterattributes/llms.txt
- **LLMs-Full URL:** https://www.textcontrol.com/blog/2023/07/25/securing-the-signature-endpoint-with-custom-actionfilterattributes/llms-full.txt

---

The HttpPost endpoint to which the signed document is forwarded can be in the same application or it can be in a completely different application. This tutorial will show you how to secure this endpoint through the use of custom filter attributes in ASP.NET Core.

### Passing a Security Token

To provide an endpoint to forward the signature data and the signed document, the *RedirectUrlAfterSignature* property can be used. For protection of this endpoint, a custom filter can be implemented and a unique security token can be passed to the HttpPost method.

The following MVC Razor code shows how to integrate the Document Viewer and the security token that is passed in the *RedirectUrlAfterSignature* property.

```
@using TXTextControl.Web.MVC.DocumentViewer

@Html.TXTextControl().DocumentViewer(settings => {
     settings.DocumentPath = "App_Data\\template.tx";
     settings.SignatureSettings = new SignatureSettings() {
      ShowSignatureBar = true,
      OwnerName = "Josh Jackson",
      SignerName = "Tim Typer",
      SignerInitials = "TT",
      UniqueId = "12345-12345-12345-12345",
      RedirectUrlAfterSignature = this.Url.Action(
        "HandleSignature",
        "Signature",
        new { secureID = "123" },
        Context.Request.Scheme,
        null),
      SignatureBoxes = new SignatureBox[] {
        new SignatureBox("txsign") { SigningRequired = true, Style = SignatureBox.SignatureBoxStyle.Signature },
        new SignatureBox("txsigninit") { SigningRequired = true, Style = SignatureBox.SignatureBoxStyle.Initials }
      }};
}).Render()
```

The above code passes the security token "123" to the specified *HandleSignature* endpoint.

### Controller Attributes

A custom *ActionFilterAttribute* *CustomActionFilter* is provided in the *HandleSignature* controller method.

```
[CustomActionFilter]
[HttpPost]
public IActionResult HandleSignature([FromBody] SignatureData data) {

  byte[] bPDF;

  // create temporary ServerTextControl
  using (TXTextControl.ServerTextControl tx = new TXTextControl.ServerTextControl()) {
    tx.Create();

    // load the document
    tx.Load(Convert.FromBase64String(data.SignedDocument.Document), TXTextControl.BinaryStreamType.InternalUnicodeFormat);

    //FlattenFormFields(tx);

    X509Certificate2 cert = new X509Certificate2("App_Data/textcontrolself.pfx", "123");

    var signatureFields = new List<DigitalSignature>();

    foreach (SignatureBox box in data.SignatureBoxes) {
      signatureFields.Add(new DigitalSignature(cert, null, box.Name));
    }

    TXTextControl.SaveSettings saveSettings = new TXTextControl.SaveSettings() {
      CreatorApplication = "Your Application",
      SignatureFields = signatureFields.ToArray()
    };

    // store the PDF in the database or send it to the client
    tx.Save(out bPDF, TXTextControl.BinaryStreamType.AdobePDFA, saveSettings);

    // alternatively, save the PDF to a file
    tx.Save("App_Data/signed.pdf", TXTextControl.StreamType.AdobePDFA, saveSettings);
  }

  // return any value to the client
  return Ok();
}
```

### Filter Implementation

The custom filter implementation compares the security token and returns an error if the token is not valid.

```
public class CustomActionFilter : ActionFilterAttribute {
  public override void OnActionExecuting(ActionExecutingContext filterContext) {
    if (filterContext.HttpContext.Request.Query["secureID"] != "123") {
      filterContext.Result = new Microsoft.AspNetCore.Mvc.ContentResult() {
        Content = "Access denied"
      };
    }
  }
}
```

In a real-world implementation, the security token would be uniquely generated server-side, stored in a database, and compared to the given parameter in the request.

---

## About Bjoern Meyer

As CEO, Bjoern is the visionary behind our strategic direction and business development, bridging the gap between our customers and engineering teams. His deep passion for coding and web technologies drives the creation of innovative products. If you're at a tech conference, be sure to stop by our booth - you'll most likely meet Bjoern in person. With an advanced graduate degree (Dipl. Inf.) in Computer Science, specializing in AI, from the University of Bremen, Bjoern brings significant expertise to his role. In his spare time, Bjoern enjoys running, paragliding, mountain biking, and playing the piano.

- [LinkedIn](https://www.linkedin.com/in/bjoernmeyer/)
- [X](https://x.com/txbjoern)
- [GitHub](https://github.com/bjoerntx)

---

## Related Posts

- [Common Web API Methods for Handling E-Signature Workflows in ASP.NET Core C#](https://www.textcontrol.com/blog/2023/07/20/common-web-api-methods-for-handling-esignature-workflows-in-aspnet-core-csharp/llms.txt)
- [High-Performance Text Replacement in Large DOCX Files using C# .NET](https://www.textcontrol.com/blog/2025/07/30/high-performance-text-replacement-in-large-docx-files-using-csharp-dotnet/llms.txt)
- [Document Viewer 33.2.1 Released: New Event and Bug Fixes](https://www.textcontrol.com/blog/2025/07/30/document-viewer-33-2-1-released-new-event-and-bug-fixes/llms.txt)
- [Building an ASP.NET Core Backend (Linux and Windows) for the Document Editor and Viewer](https://www.textcontrol.com/blog/2025/03/26/building-an-asp-net-core-backend-for-the-document-editor-and-viewer/llms.txt)
- [TX Text Control Document Editor and Viewer for Blazor Released](https://www.textcontrol.com/blog/2025/03/25/tx-text-control-document-editor-and-viewer-for-blazor-released/llms.txt)
- [Getting Started: Document Viewer for Blazor in ASP.NET Core](https://www.textcontrol.com/blog/2025/03/25/getting-started-document-viewer-for-blazor-in-asp-net-core/llms.txt)
- [Announcing Our Work on a Blazor Component for Document Editing and Viewing](https://www.textcontrol.com/blog/2025/01/24/announcing-our-work-on-a-blazor-component-for-document-editing-and-viewing/llms.txt)
- [Preparing Documents for E-Signing for Multiple Signers in .NET C#](https://www.textcontrol.com/blog/2024/11/13/preparing-documents-for-e-signing-for-multiple-signers-in-net-c-sharp/llms.txt)
- [ASP.NET Core: Use the Document Editor and Viewer in the Same Razor View](https://www.textcontrol.com/blog/2024/11/08/asp-net-core-use-the-document-editor-and-viewer-in-the-same-razor-view/llms.txt)
- [Optimizing Digital Signature Workflows: Starting with MS Word DOCX Files Instead of PDFs in C#](https://www.textcontrol.com/blog/2024/09/27/optimizing-digital-signature-workflows-starting-with-ms-word-docx-files-instead-of-pdfs-in-csharp/llms.txt)
- [Document Viewer: Setting the Rendering Mode](https://www.textcontrol.com/blog/2024/08/22/document-viewer-setting-the-rendering-mode/llms.txt)
- [View MS Word DOCX and PDF Documents using a .NET C# Document Viewer for ASP.NET Core and ASP.NET](https://www.textcontrol.com/blog/2024/08/08/view-ms-word-docx-and-pdf-documents-using-a-net-csharp-document-viewer-for-aspnet-core-and-aspnet/llms.txt)
- [Getting Started Video Tutorial: How to Add Electronic and Digital Signatures to PDF Documents in ASP.NET Core C#](https://www.textcontrol.com/blog/2024/08/05/getting-started-video-tutorial-how-to-add-electronic-and-digital-signatures-to-pdf-documents-in-asp-net-core-csharp/llms.txt)
- [Getting Started Video Tutorial: How to use the Document Viewer in ASP.NET Core C#](https://www.textcontrol.com/blog/2024/08/05/getting-started-video-tutorial-how-to-use-the-document-viewer-in-asp-net-core-csharp/llms.txt)
- [Transforming Financial Documents into Smart and Secure Forms in ASP.NET Core C#](https://www.textcontrol.com/blog/2024/05/01/transforming-financial-documents-into-smart-and-secure-forms-in-asp-net-core-c-sharp/llms.txt)
- [Document Viewer: Long Polling Support for Loading Documents](https://www.textcontrol.com/blog/2024/04/25/document-viewer-long-polling-support-for-loading-documents/llms.txt)
- [Adding and Sharing Annotations across Document Types using the Document Viewer in ASP.NET Core C#](https://www.textcontrol.com/blog/2024/04/19/adding-and-sharing-annotations-across-document-types-using-the-document-viewer-in-asp-net-core-c-sharp/llms.txt)
- [Adding a Security Middleware to ASP.NET Core Web Applications to Protect TX Text Control Document Editor and Document Viewer Endpoints](https://www.textcontrol.com/blog/2024/03/18/adding-a-security-middleware-to-asp-net-core-web-applications-to-protect-tx-text-control-document-editor-and-document-viewer-endpoints/llms.txt)
- [Building an ASP.NET Core Backend Application to Host the Document Editor and Document Viewer](https://www.textcontrol.com/blog/2024/03/14/building-an-asp-net-core-backend-application-to-host-the-document-editor-and-document-viewer/llms.txt)
- [Signature Soft Pad Customization](https://www.textcontrol.com/blog/2023/11/20/signature-soft-pad-customization/llms.txt)
- [HIPAA Compliant Electronic and Digital Signatures](https://www.textcontrol.com/blog/2023/10/27/hipaa-compliant-electronic-and-digital-signatures/llms.txt)
- [Replace Words at the Input Position with Formatted Content from a Web API](https://www.textcontrol.com/blog/2023/07/06/replace-words-at-the-input-position-with-formatted-content-from-a-web-api/llms.txt)
- [Preparing Documents for Electronic Signatures using MailMerge in C#](https://www.textcontrol.com/blog/2023/07/05/preparing-documents-for-electronic-signatures-using-mailmerge-in-csharp/llms.txt)
- [Use PDF.js to Render PDF Documents within the Document Viewer](https://www.textcontrol.com/blog/2023/03/18/use-pdfjs-to-render-pdf-documents-within-the-document-viewer/llms.txt)
- [Document Viewer 31.2.2 RC1 Released with New Features](https://www.textcontrol.com/blog/2023/03/17/document-viewer-3122-rc1-released-with-new-features/llms.txt)
