Skip to content

Commit

Permalink
Merge pull request #38 from khalidabuhakmeh/fix-antiforgery-path
Browse files Browse the repository at this point in the history
Fix `HtmxAntiforgeryScriptEndpoints.Path` #37
  • Loading branch information
khalidabuhakmeh authored Oct 23, 2023
2 parents d25882b + 76e00de commit 873aca2
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/Htmx.TagHelpers/HtmxAntiforgeryScriptEndpoints.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ namespace Htmx.TagHelpers;
public static class HtmxAntiforgeryScriptEndpoints
{
/// <summary>
/// The path to the antiforgery script that is used from HTML
/// The path to the antiforgery script that is used from HTML.
/// Note: Be sure it is rooted path ("starts with '/') or else it can break as paths get more nested.
/// </summary>
public static string Path { get; private set; } = "_htmx/antiforgery.js";
public static string Path { get; private set; } = "/_htmx/antiforgery.js";

/// <summary>
/// Register an endpoint that responds with the HTMX antiforgery script.<br/>
Expand Down
19 changes: 19 additions & 0 deletions test/Sample/Pages/Nested/Index.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
@page
@model IndexModel
@{
ViewData["Title"] = "Home page";
}

<div class="text-center">
<h1 class="display-4">Welcome</h1>
<p>Learn about <a href="https://docs.microsoft.com/aspnet/core">building Web apps with ASP.NET Core</a>.</p>
</div>

<div hx-target="this">
<button hx-post
hx-page="Index"
hx-page-handler="Snippet"
hx-swap="outerHtml">
Click Me (Razor Page w/ Handler)
</button>
</div>
20 changes: 20 additions & 0 deletions test/Sample/Pages/Nested/Index.cshtml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;

namespace Sample.Pages.Nested;

public class IndexModel : PageModel
{
public IndexModel(ILogger<IndexModel> logger)
{
}

public void OnGet()
{
}

public IActionResult OnPostSnippet()
{
return Content("<h2>Hello, World!</h2>", "text/html");
}
}

0 comments on commit 873aca2

Please sign in to comment.