From 191d401178f5f28e72e1473e9ea135dbe53c4a34 Mon Sep 17 00:00:00 2001
From: abdulrahmanshabeekmohamed
- In this article, let's learn about how to
- Note: If you have not done so already, I recommend you read the article on
-
- Few months ago as of writing this article, I was observing some
+ In this article, let's learn about how to
+ Note: If you have not done so already, I recommend you read the article on
+
+ Few months ago as of writing this article, I was observing some
- The use case of dynamic loading are,
-
+ The use case of dynamic loading are,
+
+ To implement dynamic loading, we need to store image path inside a variable in razor component and assign the image path as
+
- To implement dynamic loading, we need to store image path inside a variable in razor component and assign the image path as
-
+
+ Click on Show Image button to load the image dynamically.
+
+
-
- Click on Show Image button to load the image dynamically.
-
+
+ The advantages of dynamic loading are as follows,
- The advantages of dynamic loading are as follows,
-
+
- In this article let's learn how to prevent unauthorised use of images from crawlers in Blazor WASM apps.
-
- Note: If you have not done so already, I recommend you read the article on
-
- Every now and then somebody builds a web site with the brilliant idea that they will uses images from other people's web sites as part of their
- content.
- We can also
- First, we need to remove
-
- The below image is streamed dynamically with temporary URL. This can be verified by checking the network tab in the
- developer tools and the URL of the displayed image.
-
+
+ In this article let's learn how to prevent unauthorised use of images from crawlers in Blazor WASM apps.
- If we inspect the image element in the developer tools, we can see that the
+ Note: If you have not done so already, I recommend you read the article on
+
+ Every now and then somebody builds a web site with the brilliant idea that they will uses images from other people's web sites as part of their
+ content.
+ We can also
- When you copy that URL and try to access it via browser you get an
+ First, we need to remove
+
+ The below image is streamed dynamically with temporary URL. This can be verified by checking the network tab in the
+ developer tools and the URL of the displayed image.
+
+
+ If we inspect the image element in the developer tools, we can see that the
- As a result, it makes it more
+ When you copy that URL and try to access it via browser you get an
+ As a result, it makes it more
- The advantages of dynamic streaming are as follows,
-
+ The advantages of dynamic streaming are as follows,
+
+
+ In this article let's learn how to secure Blazor WASM app with
+ Blazor WASM app runs on Client thus cannot be trusted and just like any other JavaScript apps, any authorization can be bypassed.
+ So its very important to focus on securing the API Our Client app is talking to.
+
+ Blazor just like any other SPA Applications runs on the Client side and the most common approach is to use OAuth2 and OpenID Connect.
+ The reason behind this tokens based engineering design is,
+
+ The first step is to register the Blazor WASM app in the
+ In this demo, lets make use of the demo Identity Server provided by Duende. You can access the demo Identity Server at
+
+ The manual registration usually involves creating a
+ The next step is to install the
+ Now we need to include
- In this article let's learn how to secure Blazor WASM app with
+ The part of the app that does that is the authentication component which defines the routes required for handling different
+ authentication stages. Now lets add such a page and name it as
- Blazor WASM app runs on Client thus cannot be trusted and just like any other JavaScript apps, any authorization can be bypassed.
- So its very important to focus on securing the API Our Client app is talking to.
-
- Blazor just like any other SPA Applications runs on the Client side and the most common approach is to use OAuth2 and OpenID Connect.
- The reason behind this tokens based engineering design is,
-
- The first step is to register the Blazor WASM app in the
- In this demo, lets make use of the demo Identity Server provided by Duende. You can access the demo Identity Server at
-
- The manual registration usually involves creating a
- The next step is to install the
- Now we need to include
- The part of the app that does that is the authentication component which defines the routes required for handling different
- authentication stages. Now lets add such a page and name it as
- Now we need to configure and register
- For demo purpose, I'make using the
- Next, we need to add
- Thats it! We have successfully secured the Blazor WASM app with
-
-
+ Now we need to configure and register
- Here is the recap of complete flow.
- Initiate Login Login Redirect Enter Credentials Completing Login Initiate Log Out Processing Log Out End Session Log Out Callback Log Out Complete
- This looks awesome. We have successfully secured the Blazor WASM app with
- Passing Access tokens to API can be easily implemented by using
- Now let's see how we can shown parts of the UI to user based on authentication status. We can use
- Please login using above demo to see different section getting displayed for Bob and Alice
+
+
+ For demo purpose, I'make using the
+ Next, we need to add
- Now to get details of the user we can rely on
- This is how I display logged in user name in above demo. We can also change this to email by simply changing
-
-
- So the safe and better way is to get
- Now lets see how to secure pages from
- To make sure users are notified with right message we need to use
- To customise the default Not Authorized message we can use
- Now instead of showing custom message we can simply redirect the user to login page when they try to access a page that they are not authorized to access.
- This can be done by using
- We can also Customize the text showing in UI while authentication process is happening. This can be done in RemoteAuthenticatorView component
- by providing the LoggingIn, LogInFailed, LogOut, LogOutFailed, LogOutSucceeded RenderFragments.
-
- You can also customise the messages displayed to the user during the authentication process. The messages can be customised by providing the
-
+
+
+ Thats it! We have successfully secured the Blazor WASM app with
+
+
+ Here is the recap of complete flow.
+ Initiate Login Login Redirect Enter Credentials Completing Login Initiate Log Out Processing Log Out End Session Log Out Callback Log Out Complete
+ This looks awesome. We have successfully secured the Blazor WASM app with
+ Passing Access tokens to API can be easily implemented by using
+ Now let's see how we can shown parts of the UI to user based on authentication status. We can use
+ Please login using above demo to see different section getting displayed for Bob and Alice
+
+ Now to get details of the user we can rely on
+ This is how I display logged in user name in above demo. We can also change this to email by simply changing
+
+
+ So the safe and better way is to get
+ Now lets see how to secure pages from
+ To make sure users are notified with right message we need to use
+ To customise the default Not Authorized message we can use
+ Now instead of showing custom message we can simply redirect the user to login page when they try to access a page that they are not authorized to access.
+ This can be done by using
+ We can also Customize the text showing in UI while authentication process is happening. This can be done in RemoteAuthenticatorView component
+ by providing the LoggingIn, LogInFailed, LogOut, LogOutFailed, LogOutSucceeded RenderFragments.
+
+ You can also customise the messages displayed to the user during the authentication process. The messages can be customised by providing the
+ What we gonna do?
-
- Why we gonna do?
-
- Use Case for Dynamic Loading
+
-
+
+
+ Implementing Dynamic Loading
- How we gonna do?
-
- Implementing Dynamic Loading
+ Advantages of Dynamic Loading
- Advantages of Dynamic Loading
-
-
-
-
+
+
+ Summary
-
- What we gonna do?
-
- Why we gonna do?
-
- How we gonna do?
-
- Use Case for Dynamic Streaming
-
- Implementing Dynamic Streaming
-
- Use Case for Dynamic Streaming
+ Implementing Dynamic Streaming
+
+ Advantages of Dynamic Streaming
+ Advantages of Dynamic Streaming
-
-
-
-
+ Summary
+
+
+ What we gonna do?
+
+
+ Registering the Client
+
+ Configuring the Client
+
+ Authentication Page
+
+ Why we gonna do?
+
-
-
- How we gonna do?
-
- Registering the Client
-
- Configuring the Client
-
- Authentication Page
-
- Registering OIDC Services
-
- Redirect to Login
-
- Demo
-
-
-
-
+ Registering OIDC Services
+
+
-
-
- Passing Access Token to API
-
- Displaying parts of UI
-
- Redirect to Login
+
+
- User Details
-
- Authentication State Provider
-
- Prevent UnAuthorized Access
-
- Customization
-
- Summary
-
- Demo
+
+
+
+
+
+
+
+ Passing Access Token to API
+
+ Displaying parts of UI
+
+
+ User Details
+
+ Authentication State Provider
+
+ Prevent UnAuthorized Access
+
+ Customization
+
+
-
+
+ Imagine we're using HttpClient to get a data. Chances are that the
- Imagine we're using HttpClient to get a data. Chances are that the
+ It's important to know that cancelling a task that's no longer needed will
- It's important to know that cancelling a task that's no longer needed will
+ Note: If you have not done so already, I recommend you read the article on
+
- Note: If you have not done so already, I recommend you read the article on
-
+ To support
+ Listeners should then monitor the value of the
- To support
- Listeners should then monitor the value of the
+ All we need to do now is to initialize a
+ Note: that for demo purpose we are cancelling after 10 seconds and we are awaiting for 5 seconds to simulate the API call failure. In real world + scenario, you can set the timeout to 30 seconds or 1 minute or you can cancel when user presses cancel button. +
-
- All we need to do now is to initialize a
- Note: that for demo purpose we are cancelling after 10 seconds and we are awaiting for 5 seconds to simulate the API call failure. In real world - scenario, you can set the timeout to 30 seconds or 1 minute or you can cancel when user presses cancel button. -
++ Let's try Cancellation while reading data in this Demo, Click on the Read with Cancellation Button to see the demo on the screen. Note that + data might not be rendered on the screen as the API is cancelled before the data is read. You can verify this from the browser network log. +
+
- Let's try Cancellation while reading data in this Demo, Click on the Read with Cancellation Button to see the demo on the screen. Note that
- data might not be rendered on the screen as the API is cancelled before the data is read. You can verify this from the browser network log.
+ In this article, we learned about how to
- In this article, we learned about how to
- In this article, let's learn about how to
- Note: If you have not done so already, I recommend you read the article on
-
- There are multiple ways to Unit Test HTTP Client in dotnet. Most of the examples you will find on the internet will be using
-
- Integrating with a web API is a common task required by many applications.
- Most of the time I see developers including me say we can test HTTP Client or calls in Integration Test but
-
- Note: If you have not done so already, I recommend you read the article on
-
- You're working on a part of your application that relies on
-
- The following code shown a simple implementation of a custom message handler that returns a 401 Unauthorized response. Notice that we are using
-
- Now, we can use this custom message handler to unit test our http client. The following code shows a simple implementation of a unit test for
- http client. All we need to do is to
- Here is another similar example for
- The only drawback of this approach is that you need to write a custom message handler for each status code you want to test. I feel like we will also - need to maintain these custom message handlers. But this is the best approach I found to unit test http client in dotnet when there is no option available - to mock the http client. -
- -
+
+ In this article, let's learn about how to
+ Note: If you have not done so already, I recommend you read the article on
+
+ There are multiple ways to Unit Test HTTP Client in dotnet. Most of the examples you will find on the internet will be using
+
+ Integrating with a web API is a common task required by many applications.
+ Most of the time I see developers including me say we can test HTTP Client or calls in Integration Test but
+
+ Note: If you have not done so already, I recommend you read the article on
+
+ You're working on a part of your application that relies on
+
+ The following code shown a simple implementation of a custom message handler that returns a 401 Unauthorized response. Notice that we are using
+
+ Now, we can use this custom message handler to unit test our http client. The following code shows a simple implementation of a unit test for
+ http client. All we need to do is to
+ Here is another similar example for
+ The only drawback of this approach is that you need to write a custom message handler for each status code you want to test. I feel like we will also
+ need to maintain these custom message handlers. But this is the best approach I found to unit test http client in dotnet when there is no option available
+ to mock the http client.
+
+ In this article, let's learn about how to implement
+ I'll introduce you to the features that ASP.NET Core offers for health checks, including how to create, register, and customize them. Lets + discusses ASP.NET Core health checks, including how to configure and add health checks, create a UI to work with health checks, and secure + your health check endpoints. +
+
+ Health checks are like how we humans check our health. We go to the doctor for a regular checkup to make sure everything is fine.
+ Similarly, health checks in ASP.NET Core are used to check the
+ Health checks serve as endpoints that provide snapshot of application's health. They help to monitor the state of the application and its dependencies
+ such as
+ With health checks you can easily achieve, +
+ +
+ The app is considered
+ Health checks in ASP.NET Core are vital for enterprise and commercial development. You need to understand what's happening on your site in order to + find where problems have occurred so that in case of any failures we can be notified and take necessary actions. +
+
+ Configuring health checks involves two main steps in
+ Thats the very simple and minimal configuration. Now when you run you web api and navigate to https://localhost:5001/health, you will see the
+
+ The above setup looks neat and simple. But how do we know which part of the system is failing when we see a unhealthy status? To identify the
+
+ For example, let's add a custom health check logic to check the health of the system as shown below and register the same in the services. +
+ +
+ We can now add health check for any part of the system like database, cache, external services, etc. and register them in the services. But does this
+ seems like a lot of code? If so then you can use battle tested Health Check Library like
+
+ This Library provides a lot of built-in health checks for various services like
+
+ To add health check to
+ Now when you run you web api and navigate to https://localhost:5001/health, you will see the health check status as shown below. +
+ + + +
+ Now that said, you can
+ Having a simple string response doesn't help much. We need a UI to visualize the health check status for multiple parts of the system.
+ To create a
+ We need to
- In this article, let's learn about how to implement
- I'll introduce you to the features that ASP.NET Core offers for health checks, including how to create, register, and customize them. Lets - discusses ASP.NET Core health checks, including how to configure and add health checks, create a UI to work with health checks, and secure - your health check endpoints. -
+
+ So far so good. But what about
+ If you are looking for options to
- Health checks are like how we humans check our health. We go to the doctor for a regular checkup to make sure everything is fine.
- Similarly, health checks in ASP.NET Core are used to check the
- Health checks serve as endpoints that provide snapshot of application's health. They help to monitor the state of the application and its dependencies
- such as
+ By default, the health check endpoints are
- With health checks you can easily achieve, -
++ That's it. You have now secured the health check endpoints. +
+
- The app is considered
- Health checks in ASP.NET Core are vital for enterprise and commercial development. You need to understand what's happening on your site in order to - find where problems have occurred so that in case of any failures we can be notified and take necessary actions. -
- - - -
- Configuring health checks involves two main steps in
- Thats the very simple and minimal configuration. Now when you run you web api and navigate to https://localhost:5001/health, you will see the
-
- The above setup looks neat and simple. But how do we know which part of the system is failing when we see a unhealthy status? To identify the
-
- For example, let's add a custom health check logic to check the health of the system as shown below and register the same in the services. -
- -
- We can now add health check for any part of the system like database, cache, external services, etc. and register them in the services. But does this
- seems like a lot of code? If so then you can use battle tested Health Check Library like
-
- This Library provides a lot of built-in health checks for various services like
-
- To add health check to
- Now when you run you web api and navigate to https://localhost:5001/health, you will see the health check status as shown below. -
- - - -
- Now that said, you can
- Having a simple string response doesn't help much. We need a UI to visualize the health check status for multiple parts of the system.
- To create a
- We need to
- So far so good. But what about
- If you are looking for options to
- By default, the health check endpoints are
- That's it. You have now secured the health check endpoints. -
- - - -
+
- In this article, let's learn about how to unit test
- In ASP.NET Core,
- To know more about
- When writing software, we want to ensure that the code is covered by tests, which verify the required behavior and catch any regressions.
-
- Note: If you have not done so already, I recommend you read the article on
-
- We are going to write unit tests for the
- To unit test the
- Here is an another examples of background service using
- To unit test the
- By executing above test we can validate background services in ASP.NET Core apps. The same can be used to validate worker services in dotnet. -
- -
- Unit testing hosted services in ASP.NET Core is a crucial step to ensure that they are working as expected. By writing unit tests, you can
-
+ In this article, let's learn about how to unit test
+ In ASP.NET Core,
+ To know more about
+ When writing software, we want to ensure that the code is covered by tests, which verify the required behavior and catch any regressions.
+
+ Note: If you have not done so already, I recommend you read the article on
+
+ We are going to write unit tests for the
+ To unit test the
+ Here is an another examples of background service using
+ To unit test the
+ By executing above test we can validate background services in ASP.NET Core apps. The same can be used to validate worker services in dotnet. +
+
+ Unit testing hosted services in ASP.NET Core is a crucial step to ensure that they are working as expected. By writing unit tests, you can
+