How to enable CSRF protection on ServiceStack
1 answer
On the Razor page, you can embed the token into your form with:
<form action="/antiforgery/test" method="POST">
@Html.AntiForgeryToken()
<input name="Field" value="Test"/>
<input type="submit"/>
</form>
What can you check in your service with:
[Route("/antiforgery/test")]
public class AntiForgeryTest
{
public string Field { get; set; }
}
public class AntiForgeryService : Service
{
public object Any(AntiForgeryTest request)
{
AntiForgery.Validate();
...
}
}
+1
source to share