{"record":{"id":"a1f3a8ea74e8eb38","repo":"dotnet/machinelearning","slug":"the-provided-url-uri-redirects-to-the-default","errorCode":null,"errorMessage":"The provided url ({uri}) redirects to the default url ({DefaultUrl})","messagePattern":"The provided url \\((.+?)\\) redirects to the default url \\((.+?)\\)","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.ML.Core/Utilities/ResourceManagerUtils.cs","lineNumber":276,"sourceCode":"                mutex.ReleaseMutex();\n                return null;\n            }\n\n            Guid guid = Guid.NewGuid();\n            string tempPath = Path.GetFullPath(Path.Combine(Path.GetDirectoryName(path), \"temp-resource-\" + guid.ToString()));\n            try\n            {\n                int blockSize = 4096;\n\n                var response = await httpClient.GetAsync(uri, ct).ConfigureAwait(false);\n                using (var fh = env.CreateOutputFile(tempPath))\n                using (var ws = fh.CreateWriteStream())\n                {\n                    response.EnsureSuccessStatusCode();\n                    IEnumerable<string> headers;\n                    var hasHeader = response.Headers.TryGetValues(\"content-length\", out headers);\n                    if (uri.Host == \"aka.ms\" && IsRedirectToDefaultPage(uri.AbsoluteUri))\n                        throw new NotSupportedException($\"The provided url ({uri}) redirects to the default url ({DefaultUrl})\");\n                    if (!hasHeader || !long.TryParse(headers.First(), out var size))\n                        size = 10000000;\n\n                    var stream = await response.EnsureSuccessStatusCode().Content.ReadAsStreamAsync().ConfigureAwait(false);\n\n                    await stream.CopyToAsync(ws, blockSize, ct);\n\n                    if (ct.IsCancellationRequested)\n                    {\n                        ch.Error($\"{fileName}: Download timed out\");\n                        return ch.Except(\"Download timed out\");\n                    }\n                }\n                File.Move(tempPath, path);\n                ch.Info($\"{fileName}: Download complete\");\n                return null;\n            }\n            catch (WebException e)","sourceCodeStart":258,"sourceCodeEnd":294,"githubUrl":"https://github.com/dotnet/machinelearning/blob/7b76e69cf964daeca3f1377af6bc5543284d56c6/src/Microsoft.ML.Core/Utilities/ResourceManagerUtils.cs#L258-L294","documentation":"During resource download, ResourceManagerUtils (DownloadResource) checks whether an aka.ms URL's response actually redirects to Microsoft's default placeholder page. If so, the requested resource does not exist (aka.ms silently redirects dead links to the default page), and the code throws NotSupportedException with the redirecting URI and DefaultUrl in the message. This converts a silent 'wrong file downloaded' failure into an explicit error.","triggerScenarios":"Requesting an aka.ms short link that no longer points to a real resource; a stale/renamed resource URL shipped in an older ML.NET version; network equipment (proxy, captive portal, DNS hijack) rewriting the aka.ms response so it looks like the default redirect page.","commonSituations":"Using an older ML.NET package whose baked-in model download URLs were retired by Microsoft; corporate proxies or firewalls intercepting short-link traffic and returning a landing/default page; typos in a custom aka.ms link passed to the resource manager.","solutions":["Upgrade ML.NET to the latest version so the resource URL points to a live aka.ms link (Microsoft updates these when short links are retired).","Pre-download the resource manually and place it in the expected cache file path so the downloader is not invoked.","Inspect the thrown message's uri value and open it in a browser to confirm whether the link is dead; if dead, find the resource's current official URL.","If behind a corporate proxy, exclude aka.ms from interception/rewriting or download from a trusted network."],"exampleFix":"// before\n// relying on bundled (stale) aka.ms URL that redirects to the default page\nvar path = await ResourceManagerUtils.Instance.EnsureResourceAsync(env, ch,\n    relativeUrl, fileName, timeout);\n// after\n// check for update / pin a live URL\nif (await IsRedirectToDefaultPageAsync(resourceUrl))\n{\n    throw new InvalidOperationException(\n        $\"Resource link {resourceUrl} is stale; upgrade ML.NET or download the model manually to {cachePath}.\");\n}","handlingStrategy":"try-catch","validationCode":"using (var resp = await httpClient.GetAsync(resourceUrl, HttpCompletionOption.ResponseHeadersRead))\n{\n    var finalUri = resp.RequestMessage?.RequestUri;\n    if (finalUri != null && resourceUrl.Contains(\"aka.ms\") &&\n        finalUri.ToString().StartsWith(defaultUrl, StringComparison.OrdinalIgnoreCase))\n        throw new InvalidOperationException($\"Resource link {resourceUrl} is dead (redirects to default page).\");\n}","typeGuard":null,"tryCatchPattern":"try\n{\n    var path = await ResourceManagerUtils.Instance.EnsureResourceAsync(env, ch, relativeUrl, fileName, timeout);\n}\ncatch (NotSupportedException ex) when (ex.Message.Contains(\"redirects to the default url\"))\n{\n    // stale aka.ms link: upgrade ML.NET or download the resource manually to cachePath\n}","preventionTips":["Keep ML.NET packages up to date so bundled resource links stay live.","Pre-seed the local resource cache in offline/CI environments.","Test resource downloads after network/proxy configuration changes."],"tags":["not-supported","redirect","aka-ms","resource-download","ml-net"],"backgroundTag":"invalid-url","analyzedSha":"7b76e69cf964daeca3f1377af6bc5543284d56c6","analyzedAt":"2026-09-11T12:35:38.930Z","contentChangedAt":"2026-09-11T12:35:38.930Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}