Advertisement
Guest User

Untitled

a guest
Feb 25th, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.58 KB | None | 0 0
  1. public void Configure(IApplicationBuilder app)
  2. {
  3. app.UseMvc(); // you don't need this
  4. }
  5.  
  6. public void Configure(IApplicationBuilder app)
  7. {
  8. app.Map("/api", HandleMapApi);
  9. // notice how we don't have app.UseMvc()?
  10. }
  11.  
  12. private static void HandleMapApi(IApplicationBuilder app)
  13. {
  14. app.Run(async context =>
  15. {
  16. // implement your own response
  17. await context.Response.WriteAsync("Hello WebAPI!");
  18. });
  19. }
  20.  
  21. var builder = services.AddMvcCore();
  22.  
  23. builder.AddViews();
  24. builder.AddRazorViewEngine();
  25. builder.AddRazorPages();
  26.  
  27. public void ConfigureServices(IServiceCollection services)
  28. {
  29. // Build a customized MVC implementation, without using the default AddMvc(),
  30. // instead use AddMvcCore(). The repository link is below:
  31. // https://github.com/aspnet/Mvc/blob/dev/src/Microsoft.AspNetCore.Mvc/MvcServiceCollectionExtensions.cs
  32.  
  33. services
  34. .AddMvcCore(options =>
  35. {
  36. options.RequireHttpsPermanent = true; // this does not affect api requests
  37. options.RespectBrowserAcceptHeader = true; // false by default
  38. //options.OutputFormatters.RemoveType<HttpNoContentOutputFormatter>();
  39.  
  40. // these two are here to show you where to include custom formatters
  41. options.OutputFormatters.Add(new CustomOutputFormatter());
  42. options.InputFormatters.Add(new CustomInputFormatter());
  43. })
  44. //.AddApiExplorer()
  45. //.AddAuthorization()
  46. .AddFormatterMappings()
  47. //.AddCacheTagHelper()
  48. //.AddDataAnnotations()
  49. //.AddCors()
  50. .AddJsonFormatters();
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement