Skip to content

Commit 09c28fd

Browse files
ezverevChristy Henriksson
authored andcommitted
Appended allowRemoteCacheManagement key into web.config to allow remote cache management (clear cache). (#59)
* Appended allowRemoteCacheManagement key into web.config to allow remote cache management. * Revert "Appended allowRemoteCacheManagement key into web.config to allow remote cache management." This reverts commit daf5b2d. * Appended allowRemoteCacheManagement key into web.config to allow remote cache management. * Store web server settings in user file. * Appended allowRemoteCacheManagement key into web.config to allow remote cache management. * Revert "Appended allowRemoteCacheManagement key into web.config to allow remote cache management." This reverts commit daf5b2d. * Appended allowRemoteCacheManagement key into web.config to allow remote cache management. * Store web server settings in user file. * Update Web.config
1 parent 94ee01b commit 09c28fd

5 files changed

Lines changed: 11 additions & 13 deletions

File tree

src/NuGet.Server/Controllers/PackagesODataController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ protected PackagesODataController(IServiceResolver serviceResolver)
2929
// Exposed through ordinary Web API route. Bypasses OData pipeline.
3030
public async Task<HttpResponseMessage> ClearCache(CancellationToken token)
3131
{
32-
if (RequestContext.IsLocal)
32+
if (RequestContext.IsLocal || ServiceResolver.Current.Resolve<ISettingsProvider>().GetBoolSetting("allowRemoteCacheManagement", false))
3333
{
3434
await _serverRepository.ClearCacheAsync(token);
3535
return CreateStringResponse(HttpStatusCode.OK, "Server cache has been cleared.");

src/NuGet.Server/Core/DefaultServiceResolver.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@ public object Resolve(Type type)
5353
return _packageAuthenticationService;
5454
}
5555

56+
if (type == typeof(ISettingsProvider))
57+
{
58+
return _settingsProvider;
59+
}
60+
5661
return null;
5762
}
5863

src/NuGet.Server/Default.aspx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
<% } %>
3535
</fieldset>
3636

37-
<% if (Request.IsLocal) { %>
37+
<% if (Request.IsLocal || ServiceResolver.Current.Resolve<NuGet.Server.Core.Infrastructure.ISettingsProvider>().GetBoolSetting("allowRemoteCacheManagement", false)) { %>
3838
<fieldset style="width:800px">
3939
<legend><strong>Adding packages</strong></legend>
4040

src/NuGet.Server/NuGet.Server.csproj

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -174,16 +174,7 @@
174174
<VisualStudio>
175175
<FlavorProperties GUID="{349c5851-65df-11da-9384-00065b846f21}">
176176
<WebProjectProperties>
177-
<UseIIS>True</UseIIS>
178-
<AutoAssignPort>True</AutoAssignPort>
179-
<DevelopmentServerPort>1425</DevelopmentServerPort>
180-
<DevelopmentServerVPath>/</DevelopmentServerVPath>
181-
<IISUrl>http://localhost:40221/</IISUrl>
182-
<NTLMAuthentication>False</NTLMAuthentication>
183-
<UseCustomServer>False</UseCustomServer>
184-
<CustomServerUrl>
185-
</CustomServerUrl>
186-
<SaveServerSettingsInUserFile>False</SaveServerSettingsInUserFile>
177+
<SaveServerSettingsInUserFile>True</SaveServerSettingsInUserFile>
187178
</WebProjectProperties>
188179
</FlavorProperties>
189180
</VisualStudio>

src/NuGet.Server/Web.config

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@
6969
on a fixed 1-hour interval.
7070
-->
7171
<add key="enableFileSystemMonitoring" value="true" />
72+
<!--Set allowRemoteCacheManagement to true to enable the "clear cache" and other cache operations initiated via requests originating from remote hosts.-->
73+
<add key="allowRemoteCacheManagement" value="false" />
7274
</appSettings>
7375
<!--
7476
For a description of web.config changes see http://go.microsoft.com/fwlink/?LinkId=235367.
@@ -137,4 +139,4 @@
137139
</dependentAssembly>
138140
</assemblyBinding>
139141
</runtime>
140-
</configuration>
142+
</configuration>

0 commit comments

Comments
 (0)