question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Provide an API to configure the TempDirectory used by ASP.NET Core

See original GitHub issue

ASP.NET Core currently uses an environment variable to drive the temp directory, falling back Path.GetTempPath(). See https://github.com/aspnet/AspNetCore/blob/56e2080ef7741dea9a5c24a8e0639b0921be2d22/src/Http/Http/src/Internal/BufferingHelper.cs#L18-L39.

This path is currently in use by FileBufferingReadStream and as of https://github.com/aspnet/AspNetCore/pull/9015 change, by FileBufferingWriteStream.

This is one of the few parts of the stack that is only configurable via environment variable. We should instead follow the regular pattern of having an option type (that can be configured via configuration) and use those in when constructing these streams and everywhere else ASP.NET Core may need to write to the temp directory.

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:13 (13 by maintainers)

github_iconTop GitHub Comments

1reaction
Tratchercommented, Jun 17, 2019

We’re slowly trying to replace any APIs in the Internal namespace with fully internal or fully public types. It it’s needed by MVC and others then it needs to be in a public namespace.

0reactions
cjaliagacommented, Jun 13, 2019

Hey @Tratcher, I could use your help here 😃

Since the code of the Func<string> factory would be the same one used in the callers, I was planning on adding this method to a place that can be shared easily. I thought about adding it to the current AspNetCoreTempDirectory class in Microsoft.AspNetCore.WebUtilities which seems OK for the EnableRewind in Microsoft.AspNetcore.Http with the file linked.

//Getting options in EnableRewind
var bufferingOptions = request.HttpContext.RequestServices.GetRequiredService<IOptions<HttpBufferingOptions>>().Value;
var fileStream = new FileBufferingReadStream(body, bufferThreshold, bufferLimit, AspNetCoreTempDirectory.TempDirectoryPathFactory(bufferingOptions.TempFileDirectory));

However I’m not sure, since currently it’s internal and in the Http group of projects, if I should refer to this class from the MVC formatters same way Microsoft.AspNetcore.Http is doing, add that factory in another place, just repeat the code in all the callers, or any other option that you may think about.

//Function defined in AspNetCoreTempDirectory
public static Func<string> TempDirectoryPathFactory(string path)
{
    return () =>
    {
        // Look for folders in the following order.
        var temp = path ?? Path.GetTempPath();

        if (!Directory.Exists(temp))
        {
            throw new DirectoryNotFoundException(temp);
        }

        return temp;
    };
}

Thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Where is the ASP.NET Core 2.2 temp-directory in?
For ASP.NET MVC5 (.net4.8) the ASP.NET temporary directories are: C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.
Read more >
FileSystemConfiguration.TempDirectory Property
FileSystemConfiguration.TempDirectory Property ... Specifies the path to the directory where temporary files are stored. Namespace: DevExtreme.AspNet.Mvc.
Read more >
Tutorial: Create a web API with ASP.NET Core
This tutorial teaches the basics of building a controller-based web API that uses a database. Another approach to creating APIs in ASP.NET Core...
Read more >
Locating special folders in cross-platform .NET applications
Use .NET APIs to portably locate special folders (app and user data/confgiuration) in your cross-platform applications.
Read more >
How do I find which directory my .NET Core console ...
Every method for finding the startup assembly's location I have found, either by googling or exploring with reflection while it runs, only gives ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found