Apri PDF con la documentazione su ASP.NET Core

Configure

public void Configure(IApplicationBuilder app, IHostingEnvironment env, 
                      ILoggerFactory loggerFactory)
{
  app.UseStaticFiles(); // For the wwwroot folder
  
  /* per poter utilizzare contenuti statici fuori dal folder principale */
  app.UseStaticFiles(new StaticFileOptions()
  {
     FileProvider = new PhysicalFileProvider(
     Path.Combine(Directory.GetCurrentDirectory(), @"wwwroot", "images")),
     RequestPath = new PathString("/MyImages")
  });
  
  /* per visualizzare tramite browser il contenuto della cartella MyImages */
  app.UseDirectoryBrowser(new DirectoryBrowserOptions()
  {
     FileProvider = new PhysicalFileProvider(
     Path.Combine(Directory.GetCurrentDirectory(), @"wwwroot", "images")),
     RequestPath = new PathString("/MyImages")
  });

  /* URL MATCHING: da 'parametri di route' a 'valori di route' */ 
  /* MapAreaRoute, setta le route di sottosezioni del sito (area riservata/ blog);
     MapRoute, setta le route della parte principale dell'applicazione web; 
     Il template definisce un elenco di 'parametri di route' che dopo la gestione 
     della URL richiesto saranno inizializzati con i corrispondenti 'valori di route';
     Controller=Dashboard: valore di default del parametro di route 'controller';
     Id? ==> il punto di domanda indica  che il paramentro di route รจ opzionale; 
     Id:int ==> i : settano un route constrain per controllare il valore di ruoute; */
  app.UseMvc(routes => {
              routes.MapAreaRoute(
                name: "admin",
                areaName: "admin",
                template: "Admin/{controller=Dashboard}/{action=Index}/{id?||id:int}");
              routes.MapRoute(
                name: "blog",
                template: "Blog/{*article}",
                defaults: new { controller = "Blog", action = "ReadArticle" });
              routes.MapRoute(
                name: "default",
                template: "{controller=Home}/{action=Index}/{id?}");
              routes.MapRoute(
                name: "us_english_products",
                template: "en-US/Products/{id}",
                defaults: new { controller = "Products", action = "Details" },
                constraints: new { id = new IntRouteConstraint() },
                dataTokens: new { locale = "en-US" });

 /* per fare routing con il MIDDLEWARE bisogna aggiungere il servizio nella
    ConfigurationServices.  
    URI                            Response
    /package/create/3 Hello!       Route values: [operation, create], [id, 3]
    /package/track/-3 Hello!       Route values: [operation, track], [id, -3]
    /package/track/-3/ Hello!      Route values: [operation, track], [id, -3]
    /package/track/                <Fall through, no match>
    GET /hello/Joe                 Hi, Joe!
    POST /hello/Joe                <Fall through, matches HTTP GET only>
    GET /hello/Joe/Smith           <Fall through, no match> */
  var trackPackageRouteHandler = new RouteHandler(context =>
  {
        var routeValues = context.GetRouteData().Values;
        return context.Response.WriteAsync(
            $"Hello! Route values: {string.Join(", ", routeValues)}");
  });

  var routeBuilder = new RouteBuilder(app, trackPackageRouteHandler);

  routeBuilder.MapRoute(
        "Track Package Route",
        "package/{operation:regex(^track|create|detonate$)}/{id:int}");

  routeBuilder.MapGet("hello/{name}", context =>
  {
        var name = context.GetRouteValue("name");
        // This is the route handler when HTTP GET "hello/"  matches
        // To match HTTP GET "hello//,
        // use routeBuilder.MapGet("hello/{*name}"
        return context.Response.WriteAsync($"Hi, {name}!");
  });

  var routes = routeBuilder.Build();
  app.UseRouter(routes);

}

/* ROUTE CONSTRAINT  */ 
constraint	  Example	          Example Matches
int	          {id:int}	          123456789, -123456789
bool	          {active:bool}	          true, FALSE
datetime	  {dob:datetime}	  2016-12-31, 2016-12-31 7:32pm
decimal	          {price:decimal}	  49.99, -1,000.01
double	          {weight:double}	  1.234, -1,001.01e8
float	          {weight:float}	  1.234, -1,001.01e8
guid	          {id:guid}	          CD2C1638-1638-72D5-1638-DEADBEEF1638, 
                                          {CD2C1638-1638-72D5-1638-DEADBEEF1638}
long	          {ticks:long}	          123456789, -123456789
minlength(value)  {username:minlength(4)} Rick
maxlength(value)  {filename:maxlength(8)} Richard
length(length)	  {filename:length(12)}	  somefile.txt
length(min,max)	  {filename:length(8,16)} somefile.txt
min(value)	  {age:min(18)}	          19
max(value)	  {age:max(120)}	  91
range(min,max)	  {age:range(18,120)}	  91
alpha	          {name:alpha}	          Rick
regex(expression) {ssn:regex(^\\d{{3}}-\\d{{2}}-\\d{{4}}$)}	123-45-6789
required	  {name:required}	  Rick 

/* URL GENERATION: da 'valori di route' a 'parametri di route' */
app.Run(async (context) =>
{
    var dictionary = new RouteValueDictionary
    {
        { "operation", "create" },
        { "id", 123}
    };

    var vpc = new VirtualPathContext(context, null, dictionary, "Track Package Route");
    var path = routes.GetVirtualPath(vpc).VirtualPath;

    context.Response.ContentType = "text/html";
    await context.Response.WriteAsync("Menu"); 
    await context.Response.WriteAsync($"Create Package 123"); 
}); 

Configure Service
public void ConfigureServices(IServiceCollection services)
{
    services.AddRouting();
}