Home
Projects
Gear
Privacy
Contact Us
GitHub
Code
Our Github Repository
BBAI Backup Cam
Ghost Catcher Cam
Social Distance Desk Ornament
Ultrasonic Security Alarm
R2D2
Coke Drum IoT
Spider Man Web Slinger
Modbus Mega Logger
Ultimate Trike
Clock Crane
Jumbo Laser Etcher
Marshmallow-Rotisserie
Contact Us
ID:
Title:
Lead:
Signature:
<p>Cross Origin Resource Sharing (CORS) provides browsers a way to request remote URLs only when they have permission. Razor Pages by default will prevent a Form that originated somewhere else from posting to the page handler. However, sometimes you might want to do that. </p> <p>Troubleshooting package integration was my reason. I wanted to test out TinyMCE's <em>upload image</em> feature. It has its own uploader that you provide your endpoint to. Unfortunately, it doesn't bring in any other form fields when it posts, so the AntiforgeryToken automatically placed by ASP.Net isn't included with the post. I tried the custom upload code option, but still couldn't get it to land. I spent several hours beating my head against the keyboard trying to get it to return anything but "Bad Request". I finally thought to disable the AntiForgery and, poof, it worked.</p> <p>Here is a snippet:</p> <pre class="language-csharp"><code>namespace raw.Pages { [IgnoreAntiforgeryToken(Order = 1001)] public class EditModel : PageModel {... } }</code></pre> <p>The magic part is, of course, IgnoreAntiforgeryToken. So, the next time you are having trouble getting yoru jQuery AJAX to successfully post to your .Net code, give this a try. Placing it at the page model will have it affect solely that page - not your entire site.</p>
View in New Tab
Copied! Use Ctrl-V to paste it back at your terminal.
Close