feat: change SqlSessionStateProviderAsync.GetConnectionString to allow override

This commit is contained in:
Lucas Schwendler 2024-05-30 11:01:03 +02:00
Родитель 7655d1fae1
Коммит 8b18259234
2 изменённых файлов: 24 добавлений и 18 удалений

Просмотреть файл

@ -92,7 +92,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Data.SqlClient">
<Version>5.0.0</Version>
<Version>5.2.0</Version>
</PackageReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />

Просмотреть файл

@ -384,8 +384,29 @@ namespace Microsoft.AspNet.SessionState
public override bool SetItemExpireCallback(System.Web.SessionState.SessionStateItemExpireCallback expireCallback)
{
return false;
}
}
/// <summary>
/// Retrieve the connection string based on the connectionstring name
/// </summary>
/// <param name="connectionstringName">string</param>
/// <returns></returns>
protected virtual ConnectionStringSettings GetConnectionString(string connectionstringName)
{
if (string.IsNullOrEmpty(connectionstringName))
{
throw new ProviderException(SR.Connection_name_not_specified);
}
ConnectionStringSettings conn = ConfigurationManager.ConnectionStrings[connectionstringName];
if (conn == null)
{
throw new ProviderException(
String.Format(CultureInfo.CurrentCulture, SR.Connection_string_not_found, connectionstringName));
}
return conn;
}
private async Task<GetItemResult> DoGet(HttpContextBase context, string id, bool exclusive, CancellationToken cancellationToken)
{
if (id.Length > SessionIDManager.SessionIDMaxLength)
@ -585,21 +606,6 @@ namespace Microsoft.AspNet.SessionState
{
Interlocked.CompareExchange(ref s_inPurge, 0, 1);
}
}
private static ConnectionStringSettings GetConnectionString(string connectionstringName)
{
if (string.IsNullOrEmpty(connectionstringName))
{
throw new ProviderException(SR.Connection_name_not_specified);
}
ConnectionStringSettings conn = ConfigurationManager.ConnectionStrings[connectionstringName];
if (conn == null)
{
throw new ProviderException(
String.Format(CultureInfo.CurrentCulture, SR.Connection_string_not_found, connectionstringName));
}
return conn;
}
}
}
}