Skip to content
代码片段 群组 项目
未验证 提交 34d1f497 编辑于 作者: Safia Abdalla's avatar Safia Abdalla 提交者: GitHub
浏览文件

Fix up parsing of IIS settings in user-jwts (#42350)

上级 4bafffff
No related branches found
No related tags found
无相关合并请求
......@@ -114,13 +114,19 @@ internal static class DevJwtCliHelpers
ArgumentException.ThrowIfNullOrEmpty(nameof(project));
var launchSettingsFilePath = Path.Combine(Path.GetDirectoryName(project)!, "Properties", "launchSettings.json");
var applicationUrls = new List<string>();
var applicationUrls = new HashSet<string>();
if (File.Exists(launchSettingsFilePath))
{
using var launchSettingsFileStream = new FileStream(launchSettingsFilePath, FileMode.Open, FileAccess.Read);
if (launchSettingsFileStream.Length > 0)
{
var launchSettingsJson = JsonDocument.Parse(launchSettingsFileStream);
if (ExtractIISExpressUrlFromProfile(launchSettingsJson.RootElement) is { } iisUrls)
{
applicationUrls.UnionWith(iisUrls);
}
if (launchSettingsJson.RootElement.TryGetProperty("profiles", out var profiles))
{
var profilesEnumerator = profiles.EnumerateObject();
......@@ -128,25 +134,20 @@ internal static class DevJwtCliHelpers
{
if (ExtractKestrelUrlsFromProfile(profile) is { } kestrelUrls)
{
applicationUrls.AddRange(kestrelUrls);
}
if (ExtractIISExpressUrlFromProfile(profile) is { } iisUrls)
{
applicationUrls.AddRange(iisUrls);
applicationUrls.UnionWith(kestrelUrls);
}
}
}
}
}
return applicationUrls;
return applicationUrls.ToList();
static List<string> ExtractIISExpressUrlFromProfile(JsonProperty profile)
static List<string> ExtractIISExpressUrlFromProfile(JsonElement rootElement)
{
if (profile.NameEquals("iisSettings"))
if (rootElement.TryGetProperty("iisSettings", out var iisSettings))
{
if (profile.Value.TryGetProperty("iisExpress", out var iisExpress))
if (iisSettings.TryGetProperty("iisExpress", out var iisExpress))
{
List<string> iisUrls = new();
if (iisExpress.TryGetProperty("applicationUrl", out var iisUrl))
......
......@@ -25,16 +25,16 @@ public class UserJwtsTestFixture : IDisposable
private const string LaunchSettingsTemplate = @"
{
""iisSettings"": {
""windowsAuthentication"": false,
""anonymousAuthentication"": true,
""iisExpress"": {
""applicationUrl"": ""http://localhost:23528"",
""sslPort"": 44395
}
},
""profiles"": {
""iisSettings"": {
""windowsAuthentication"": false,
""anonymousAuthentication"": true,
""iisExpress"": {
""applicationUrl"": ""http://localhost:23528"",
""sslPort"": 44395
}
},
""HttpApiSampleApp"": {
""HttpWebApp"": {
""commandName"": ""Project"",
""dotnetRunMessages"": true,
""launchBrowser"": true,
......@@ -42,6 +42,22 @@ public class UserJwtsTestFixture : IDisposable
""environmentVariables"": {
""ASPNETCORE_ENVIRONMENT"": ""Development""
}
},
""HttpsOnly"": {
""commandName"": ""Project"",
""dotnetRunMessages"": true,
""launchBrowser"": true,
""applicationUrl"": ""https://localhost:5001"",
""environmentVariables"": {
""ASPNETCORE_ENVIRONMENT"": ""Development""
}
},
""IIS Express"": {
""commandName"": ""IISExpress"",
""launchBrowser"": true,
""environmentVariables"": {
""ASPNETCORE_ENVIRONMENT"": ""Development""
}
}
}
}";
......
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册