Static files are stored in Core Web In the root directory . The default directory is <content_root>/wwwroot, But through UseWebRoot Method to change the access directory . and content_root Refer to web All folders of the project , Include bin and wwwroot Folder .


Simple configuration

stay Configure Set in method

app.UseStaticFiles();// The default static file directory is wwwroot

Modify the default static file directory

stay Configure Set in method

StaticFiles(app, env);

StaticFiles Method

        /// <summary>
/// Static files
/// </summary>
/// <param name="app"></param>
/// <param name="env"></param>
/// <returns></returns>
private void StaticFiles(IApplicationBuilder app, IWebHostEnvironment env)
// Static file overload
app.UseStaticFiles(new StaticFileOptions
FileProvider = new PhysicalFileProvider(Path.Combine(env.ContentRootPath, "Upload")), // Switch the directory to the static file directory
RequestPath =new PathString("/fileupload"), // Virtual paths are used to access static files
OnPrepareResponse = ctx =>
const int cacheControl = 60;// Set the time to cache static files
var headers = ctx.Context.Response.GetTypedHeaders();
headers.CacheControl = new CacheControlHeaderValue
MaxAge = TimeSpan.FromSeconds(cacheControl)

We're in the project directory Upload Create a new folder 1.txt file , This is when we start the project , You can go through the address :http://localhost:8001/fileupload/1.txt Get the contents of the file .

WeChat official account

.Net More articles on static resources

  1. spring Interceptor exclusion Static resources

    Interceptors need to exclude static resources , Otherwise, it will cause waste of resources <!-- Interceptor --> <mvc:interceptors> <!-- Use bean Define a Interceptor, Direct definition ...

  2. HappyAA Server deployment notes 2(nginx Static resource cache configuration for )

    I've recently made a few server improvements , Although I used nginx After the reverse proxy, the performance is improved , But still not enough , We need to use caching to greatly improve the access speed of static resources . These are the main static resources on the server :png, jpg, svg, j ...

  3. Spring MVC Processing static resource files

    Abstract :  Three programs : 1. Scheme 1 : Activate Tomcat Of defaultServlet To handle static files 2. Option two : stay spring3.0.4 Later versions are available mvc:resources ( Need configuration annotati ...

  4. Spring Boot Medium and static resources (JS, picture ) Where should I put it

    Spring Boot Static resources for , For example, where should the picture be placed , If you put it in the traditional WEB Similar places in total , such as webapp perhaps WEB-INF Next , You'll get a broken image that the sketch file didn't find . Where should I put it ?  Baidu one ...

  5. utilize filter Mechanism to Static resources url Add a time stamp , To prevent js and css File cache , It's good for development and debugging

    Go straight to the code : public class WeiXinFilter implements Filter{ private static Logger logger = LoggerFactory.get ...

  6. Spring MVC Access static resources

    When we don't go through the controller , When you want to directly access static resources on the website , because DispatcherServlet Of url-patten The restriction of the wildcard , Cause the system to think you're visiting a url mapping , At this time, you need to configure something to solve the problem ...

  7. Django 1.10 No static resource solution found

    Test version :Django 1.10 problem :Django Project cannot find static resource resolvent : 1. First of all, you need to be in your own app Create below 2 A catalog static and   templates The tree structure is as follows (DjangoPr ...

  8. ASP.NET MVC Notes on static resource packaging and compression

    ASP.NET MVC There was a BundleConfig For packaging and compression of static resources , I encountered some problems in the process of using , Now let's summarize , And give specific solutions . Question 1 : Packed and compressed JavaScript and ...

  9. Spring MVC Static resource processing

    grace REST Style resources URL Do not want to bring .html or .do Equisuffix . Because of the early Spring MVC Can't handle static resources well , So in web.xml Middle configuration DispatcherServlet Request mapping for , Often ...

  10. TCP/IP Learning agreement ( Four ) be based on C# Socket Of Web The server --- Static resource processing

    Catalog 1. C# Socket Communications 2. HTTP Parsing engine 3. Resource read and return 4. Server testing and code download Web Server is Web The host of resources , It needs to handle requests from the client browser , And specify the corresponding Web Resource return ...

Random recommendation

  1. linux Kernel analysis job : In a simple way C Program, for example , Analyze assembly code to understand how a computer works

    One . experiment Use gcc –S –o main.s main.c -m32 Command into assembly code , Please modify the numbers in the following code to avoid being similar to others int g(int x) { return x + 3; } in ...

  2. android support The role of and solutions to common mistakes

    *:first-child { margin-top: 0 !important; } body>*:last-child { margin-bottom: 0 !important; } /* ...

  3. C# About moving controls up, down, left, right

    C# How to make the control move up, down, left and right ?( turn ) stay winform Capture the key events of control keys such as up, down, left and right keys in ( turn ) http://blog. ...

  4. Native js obtain execl The value of the inside The main use of ActiveXObject

    Today a programmer gave a excel surface , There are more than 100 pieces of data in it , Call me to copy the data one by one into the corresponding functions, such as put("gaga1","gaga2"), In a word , Want me ...

  5. Android(java) Learning notes 252:ContentProvider The content observer of use 01

    1. Content watchers It's not part of the four components , Just content providers ContentProvider Corresponding small functions . If you find that the contents of the database have changed , You'll see right away . Here's the logic diagram :       When A In the application, the data inside the bank changes ...

  6. Close and release JDBC

    I saw a piece of code in the project today , Connection conn = null;  ResultSet rs = null;  PreparedStatement pss = null;  try  {  ...

  7. WebView, I have grown up , Know if you're safe !

    One . Preface If you're using Android Native system (Google Play service ), In the use of WebView When loading some web pages , I must have met the following red screen of safety warning . This is a WebView Security browsing protection strategy of , stay A ...

  8. One 1 At the same time on the basis of level grouping 2 It's divided into two groups SQL Interview questions

    Example 1: Test data : SQL> select * from score; ID CLASS STUDENT COURSE      SCORE ---------- ----- ------- - ...

  9. [py] Class

    Continue to summarize some of the special methods used in the class Look at the source code, you will always see some strange writing : Mixed with design patterns ...

  10. Flex Learning notes - Custom menu display details

    icon <?xml version="1.0" encoding="utf-8"?> <s:Application xmlns:fx=&qu ...