public void Configure(IApplicationBuilder app) { // app.UseDefaultFiles(); app.UseStaticFiles(); app.Use(async(context, next) => { context.Response.ContentType = "text/html"; await next(); }); // next steps solution app.Map("/quote", builder => builder.Run(async context => { var id = int.Parse(context.Request.Path.ToString().Split('/')[1]); var quote = QuotationStore.Quotations[id]; await context.Response.WriteAsync(quote.ToString()); })); app.Map("/all", builder => builder.Run(async context => { foreach (var quote in QuotationStore.Quotations) { await context.Response.WriteAsync("<div>"); await context.Response.WriteAsync(quote.ToString()); await context.Response.WriteAsync("</div>"); } })); app.Run(context => { return(context.Response.WriteAsync(QuotationStore.RandomQuotation().ToString())); }); }
public void Configure(IApplicationBuilder app, IOptions <List <Quotation> > quoteOptions) { //app.UseStatusCodePages("text/plain","HTTP Status Code: {0}"); app.UseStatusCodePagesWithRedirects("~/{0}.html"); app.UseDeveloperExceptionPage(); app.UseStaticFiles(); var quotes = quoteOptions.Value; if (quotes != null) { QuotationStore.Quotations = quotes; } app.Map("/quote", builder => builder.Run(async context => { var id = int.Parse(context.Request.Path.ToString().Split('/')[1]); var quote = QuotationStore.Quotations[id]; await context.Response.WriteAsync(quote.ToString()); })); app.Map("/all", builder => builder.Run(async context => { foreach (var quote in QuotationStore.Quotations) { await context.Response.WriteAsync("<div>"); await context.Response.WriteAsync(quote.ToString()); await context.Response.WriteAsync("</div>"); } })); app.Map("/random", builder => builder.Run(async context => { await context.Response.WriteAsync(QuotationStore.RandomQuotation().ToString()); })); }