Posts

Showing posts with the label dotnet interview

Custom filters of asp.net core api

Image
Custom filters in ASP.NET Core Web APIs offer a powerful way to implement specific authentication logic beyond what built-in filters provide. Here's a breakdown of how to create and use them: Creating Custom Authentication Filters: 1. Inheritance: Your custom filter class typically inherits from AuthorizeAttribute or the IAuthorizationFilter interface.        AuthorizeAttribute: This is a simpler approach if your filter primarily relies on properties from the base class (like Roles or AuthenticationSchemes).       IAuthorizationFilter: This interface offers more control over the authorization process. You'll need to implement the OnAuthorization method to perform custom validation logic. 2. Custom Validation Logic: Within the OnAuthorization method (for IAuthorizationFilter ) or using properties like Roles and AuthenticationSchemes (for AuthorizeAttribute ), implement your authentication logic. This logic might involve:   ...

Authentication Filters in Web APIs in dotnet core

Image
In ASP.NET Core Web APIs, authentication filters provide a powerful mechanism to secure your API endpoints. Here's a breakdown specifically for .NET Core: How it Works: Pipeline Integration: When a request hits your Web API, it goes through a series of processing stages called the pipeline. Authentication filters are registered within this pipeline. Filter Activation: Depending on the scope (global, controller, or action), specific filters are triggered for each request. Credential Validation: The filter inspects the request for credentials based on the configured authentication scheme. This could involve: Headers: Examining specific headers for API keys or tokens. Body: Checking for username and password combinations in the request body (common for basic authentication). Other Mechanisms: Depending on the scheme, credentials might be retrieved from cookies or URL parameters. IPrincipal Creation: If credentials are valid according to the filter's logic,...

Difference between page load and document.ready?

Image
`document.ready` and "page load" refer to two different events in the lifecycle of a web page. 1. Page Load: This event occurs when all the resources on a web page, including images, scripts, stylesheets, etc., have finished downloading and rendering. It signifies that the entire HTML document, along with its associated resources, has been loaded and is ready for interaction. This event is triggered by the browser's `load` event. 2. `document.ready`: This event, often associated with jQuery, occurs when the DOM (Document Object Model) hierarchy is fully constructed, but before the browser has finished rendering the page. It means that the DOM elements are ready to be manipulated via JavaScript or jQuery, but some external resources like images may still be loading. It is triggered by jQuery's `$(document).ready()` function or its shorthand `$(function() { ... })`. In summary, "page load" refers to the complete loading of all resources on a page, ...