Use jQuery Unobtrusive Ajax for HTML replacement via data-* attributes
masterdata-* attributes. This enables declarative Ajax behavior for HTML replacement without writing manual JavaScript for every call.repository·master·Indexed 42 days ago
https://github.com/vahidn/dntcaptcha.coreA captcha generator and validator for ASP.NET Core applications. It supports various storage providers (Session, MemoryCache, Cookie, and Distributed Cache), multiple display modes like NumberToWord and SumOfTwoNumbers, and integrates with UI frameworks like Bootstrap. It includes a tag helper for Razor views and a [ValidateDNTCaptcha] attribute for controller validation.
data-* attributes. This enables declarative Ajax behavior for HTML replacement without writing manual JavaScript for every call.data-* attributes. This enables declarative Ajax behavior for HTML replacement without writing manual JavaScript for every call.data-* elements, enabling a more declarative approach to handling Ajax calls in the markup.data-* attributes on your elements, rather than writing manual JavaScript validation logic. This approach is commonly used in ASP.NET Core applications to bridge the gap between server-side model metadata and client-side validation.Choosing a storage provider depends on your deployment architecture:
UseSessionStorageProvider() or UseMemoryCacheStorageProvider() because session state is stored in local RAM and will be lost if the instance moves or restarts. Instead, use UseCookieStorageProvider() or UseDistributedCacheStorageProvider() (e.g., with Redis) to ensure state persists across different server instances.$.validator.addMethod() or adjust built-in patterns via $.validator.methods().The Bootstrap distribution includes compiled CSS and JS, minified versions, and source maps.
Key components:
bootstrap.*: Compiled CSS and JS.bootstrap.min.*: Minified versions for production.bootstrap.*.map: Source maps for browser developer tools.bootstrap.bundle.js / bootstrap.bundle.min.js: JS files that include Popper bundled inside.css/: Contains grid, reboot, and utility styles, including RTL (Right-to-Left) support.js/: Contains ESM (ES Modules) and standard JS builds.bootstrap/
├── css/
│ ├── bootstrap-grid.css
│ ├── bootstrap-grid.min.css
│ ├── bootstrap-grid.rtl.min.css
│ ├── bootstrap-reboot.min.css
│ ├── bootstrap-utilities.min.css
│ ├── bootstrap.css
│ ├── bootstrap.min.css
│ └── bootstrap.rtl.min.css
└── js/
├── bootstrap.bundle.js
├── bootstrap.bundle.min.js
├── bootstrap.esm.js
├── bootstrap.esm.min.js
├── bootstrap.js
└── bootstrap.min.jsTo run the full demonstration environment consisting of the DNTCaptcha.TestApiApp backend and the DntCaptchaAngularClient frontend, follow these steps:
DNTCaptcha.TestApiApp project using your IDE (Visual Studio or Rider) or via the CLI using dotnet watch run.DNTCaptcha.AngularClient/ directory and run npm install.DNTCaptcha.AngularClient/ directory, execute ng serve or npm run start.http://localhost:4200.Note: The Angular client is designed to work with the DNTCaptcha.TestApiApp backend.
# 1. Start backend
dotnet watch run
# 2. Install frontend dependencies
cd DNTCaptcha.AngularClient/
npm install
# 3. Start frontend
ng serveBy default, the plugin outputs error messages in a <label> element. To improve screen reader support and avoid having multiple <label> elements for a single input, use the errorElement parameter in the validate() method.
When you specify an element (e.g., "span"), the plugin automatically adds aria-describedby to the input field and links it to the error element, ensuring better programmatic association for assistive technologies.
```js
// Configuration
$("#myform").validate({
errorElement: "span"
});<!-- Resulting HTML Structure --> <label for="name">Name</label> <input id="name" aria-describedby="unique-id-here"> <span class="error" id="unique-id-here">This field is required</span>
The jQuery Validation Plugin provides drop-in validation for existing forms. You can download prebuilt files from jqueryvalidation.org or obtain the latest development files by building the repository using grunt.
To use the plugin, include both jQuery and jquery.validate.js on your page, then call the .validate() method on your form selector.
<form>
<input required>
</form>
<script src="jquery.js"></script>
<script src="jquery.validate.js"></script>
<script>
$("form").validate();
</script>If your application is running behind a reverse proxy (like a load balancer), you must add the forwarded headers middleware to ensure correct request processing. Configure ForwardedHeadersOptions with the appropriate headers and known proxy IP addresses.
services.Configure<ForwardedHeadersOptions>(options =>
{
options.ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto;
options.KnownProxies.Add(IPAddress.Parse("my load balancer ip 1"));
options.KnownProxies.Add(IPAddress.Parse("my load balancer ip 2"));
});DNTCaptcha is compatible with modern Single Page Application (SPA) architectures:
dntcaptcha-angular-client package. A sample implementation includes a server-side controller, a dedicated Angular component, and a login component integration.