@@ -47,6 +47,12 @@ public PhysicalFileSystemProvider(
4747
4848 this . providerRootPath = GetProviderRoot ( options . Value , environment . WebRootPath , environment . ContentRootPath ) ;
4949 this . formatUtilities = formatUtilities ;
50+
51+ // Disable provider by default when no root path is configured or webroot doesn't exist
52+ if ( this . providerRootPath == null )
53+ {
54+ this . Match = _ => false ;
55+ }
5056 }
5157
5258 /// <inheritdoc/>
@@ -87,12 +93,32 @@ public Task<IImageResolver> GetAsync(HttpContext context)
8793 /// <returns><see cref="string"/> representing the fully qualified provider root path.</returns>
8894 internal static string GetProviderRoot ( PhysicalFileSystemProviderOptions providerOptions , string webRootPath , string contentRootPath )
8995 {
90- string providerRoot = providerOptions . ProviderRootPath ?? webRootPath ?? "wwwroot" ;
91- string fullPath = Path . IsPathFullyQualified ( providerRoot )
92- ? providerRoot
93- : Path . GetFullPath ( providerRoot , contentRootPath ) ;
96+ string providerRootPath = providerOptions . ProviderRootPath ?? webRootPath ;
97+ if ( providerRootPath == null )
98+ {
99+ // Default to /wwwroot if it exists
100+ string wwwroot = Path . Combine ( contentRootPath , "wwwroot" ) ;
101+ if ( Directory . Exists ( wwwroot ) )
102+ {
103+ providerRootPath = wwwroot ;
104+ }
105+ }
106+
107+ if ( ! string . IsNullOrEmpty ( providerRootPath ) )
108+ {
109+ string fullPath = Path . IsPathFullyQualified ( providerRootPath )
110+ ? providerRootPath
111+ : Path . GetFullPath ( providerRootPath , contentRootPath ) ;
112+
113+ if ( ! Directory . Exists ( fullPath ) )
114+ {
115+ Directory . CreateDirectory ( fullPath ) ;
116+ }
117+
118+ return EnsureTrailingSlash ( fullPath ) ;
119+ }
94120
95- return EnsureTrailingSlash ( fullPath ) ;
121+ return null ;
96122 }
97123
98124 internal static string EnsureTrailingSlash ( string path )
0 commit comments