File tree Expand file tree Collapse file tree 1 file changed +13
-0
lines changed
BlazorPreRender/BlazorApp1/BlazorApp1.Server Expand file tree Collapse file tree 1 file changed +13
-0
lines changed Original file line number Diff line number Diff line change 11using Microsoft . AspNetCore . Builder ;
22using Microsoft . AspNetCore . Hosting ;
3+ using Microsoft . AspNetCore . Hosting . Server ;
4+ using Microsoft . AspNetCore . Hosting . Server . Features ;
35using Microsoft . Extensions . DependencyInjection ;
46using Microsoft . Extensions . Hosting ;
7+ using System ;
8+ using System . Linq ;
9+ using System . Net . Http ;
510
611namespace BlazorApp1 . Server
712{
@@ -10,6 +15,14 @@ public class Startup
1015 public void ConfigureServices ( IServiceCollection services )
1116 {
1217 services . AddRazorPages ( ) ;
18+
19+ services . AddSingleton < HttpClient > ( sp =>
20+ {
21+ var server = sp . GetRequiredService < IServer > ( ) ;
22+ var addressFeature = server . Features . Get < IServerAddressesFeature > ( ) ;
23+ var baseAddress = addressFeature . Addresses . First ( ) ;
24+ return new HttpClient { BaseAddress = new Uri ( baseAddress ) } ;
25+ } ) ;
1326 }
1427
1528 public void Configure ( IApplicationBuilder app , IWebHostEnvironment env )
You can’t perform that action at this time.
0 commit comments