File tree Expand file tree Collapse file tree 1 file changed +44
-0
lines changed
sessions/Season-05/0505-ApiDesignAndDevelopment Expand file tree Collapse file tree 1 file changed +44
-0
lines changed Original file line number Diff line number Diff line change @@ -89,11 +89,55 @@ You will need to [extend the configuration of Kestrel](https://docs.microsoft.co
89
89
90
90
Blog at: https://devblogs.microsoft.com/aspnet/jwt-validation-and-authorization-in-asp-net-core/
91
91
92
+ ## Configuring CORS
93
+
94
+ Cross-Origin Resource Sharing (CORS) can be configured in your application with a policy using settings like the following:
95
+
96
+ ``` csharp
97
+
98
+ public void ConfigureServices (IServiceCollection services )
99
+ {
100
+
101
+ .. .
102
+
103
+ services .AddCors (options =>
104
+ {
105
+ options .AddPolicy (name : " MyPolicy" ,
106
+ builder =>
107
+ {
108
+ builder .AllowAnyOrigin ();
109
+ .AllowAnyHeader ();
110
+ });
111
+ });
112
+
113
+
114
+ }
115
+
116
+ ```
117
+
118
+ and then add the CORS policy to the HTTP pipeline with:
119
+
120
+ ``` csharp
121
+ app .UseRouting ();
122
+
123
+ app .UseCors (" MyPolicy" );
124
+
125
+ app .UseAuthorization ();
126
+ ```
127
+
92
128
## Connecting to a front-end framework
93
129
94
130
With Blazor, use ` HttpClient ` to request and interact with data from the server:
95
131
132
+ ``` csharp
133
+ await Http .GetFromJsonAsync <WeatherForecast []>(" https://localhost:5011/WeatherForecast" );
134
+ ```
135
+
136
+ We can add headers using standard ` HttpClient.DefaultRequestHeaders ` properties:
96
137
138
+ ``` csharp
139
+ Http .DefaultRequestHeaders .Add (" X-ApplicationId" , " My Blazor App" );
140
+ ```
97
141
98
142
## Deploying - Docker, Azure, etc
99
143
You can’t perform that action at this time.
0 commit comments