Esempio n. 1
0
    public async void Configure(IApplicationBuilder app, WorldContextSeedData seeder, ILoggerFactory loggerFactory)
    {
            loggerFactory.AddDebug(LogLevel.Warning);

            app.UseStaticFiles();

            app.UseIdentity();

            Mapper.Initialize(config =>
            {
                config.CreateMap<Trip, TripViewModel>().ReverseMap();
                config.CreateMap<Stop, StopViewModel>().ReverseMap();
            });

            app.UseMvc(config =>
              {
                config.MapRoute(
                  name: "Default",
                  template: "{controller}/{action}/{id?}",
                  defaults: new { controller = "App", action = "Index" }
                  );
      });

      await seeder.EnsureSeedData();
    }
Esempio n. 2
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public async void Configure(IApplicationBuilder app, WorldContextSeedData wcsd,ILoggerFactory loggerFactory)
        {
            //you could add provider to log to a db
            loggerFactory.AddDebug(LogLevel.Warning);

            app.UseStaticFiles();

            app.UseIdentity();

            AutoMapper.Mapper.Initialize(config =>
            {
                //map both way through anon method
                config.CreateMap<Trip, TripViewModel>().ReverseMap();
                config.CreateMap<Stop, StopViewModel>().ReverseMap();
            });

            app.UseMvc(config => 
            {
                config.MapRoute(
                    name: "Default",
                    template: "{controller}/{action}/{id?}",
                    defaults: new { controller = "App", action = "index" }
                    );
            });
            //used code first migrations
            await wcsd.EnsureSeedData();
        }
Esempio n. 3
0
        public async void Configure(IApplicationBuilder app, WorldContextSeedData seeder, ILoggerFactory loggerfactory)
        {
            loggerfactory.AddDebug(LogLevel.Information);

            app.UseStaticFiles(); // allow usage of static files

            app.UseIdentity(); // allow use of the identity 

            Mapper.Initialize(config =>
            {
                config.CreateMap<Trip, TripViewModel>().ReverseMap();
                config.CreateMap<Stop, StopViewModel>().ReverseMap();
            }); //specify the different config for each types. Optimizes it.

            //start Mvc with the specified map route
            app.UseMvc(config =>
            {
                config.MapRoute(
                    name: "Default",
                    template: "{controller}/{action}/{id?}",
                    defaults: new {controller = "App", action = "Index"}
                    );
            });

            await seeder.EnsureSeedDataAsync();
        }
Esempio n. 4
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, WorldContextSeedData seeder, ILoggerFactory loggerFactory)
        {
            if (env.IsDevelopment())
            {
                loggerFactory.AddDebug(LogLevel.Warning);

                app.UseDeveloperExceptionPage();

                app.UseDatabaseErrorPage(options =>
                {
                    options.EnableAll();
                });

                app.UseRuntimeInfoPage(); // default path is /runtimeinfo
            }
            else
            {
                // specify production behavior for error handling, for example:
                // app.UseExceptionHandler("/Home/Error");
                // if nothing is set here, exception will not be handled.
            }

            app.UseStaticFiles();

            app.UseMvc(config =>
            {
                config.MapRoute(
                    name: "Default",
                    template: "{controller}/{action}/{id?}",
                    defaults: new { controller = "App", action = "Index" }
                );
            });

            seeder.EnsureSeedData();
        }
Esempio n. 5
0
    // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
    public void Configure(IApplicationBuilder app, WorldContextSeedData seeder, ILoggerFactory loggerFactory)
    {
      loggerFactory.AddDebug(LogLevel.Warning);

      app.UseStaticFiles();

      app.UseMvc(config =>
      {
        config.MapRoute(
          name: "Default",
          template: "{controller}/{action}/{id?}",
          defaults: new { controller = "App", action = "Index" }
          );
      });

      seeder.EnsureSeedData();

    }
Esempio n. 6
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public async void Configure(IApplicationBuilder app, WorldContextSeedData seeder, ILoggerFactory loggerFactory, IHostingEnvironment environment)
        {

            if (environment.IsDevelopment())
            {
                loggerFactory.AddDebug(LogLevel.Information);
                app.UseDeveloperExceptionPage();
            }
            else
            {
                loggerFactory.AddDebug(LogLevel.Error);
                app.UseDeveloperExceptionPage();
            }

 

            app.UseStaticFiles();

            app.UseIdentity();

            Mapper.Initialize(config =>
            {
                config.CreateMap<Trip, TripViewModel>().ReverseMap();
                config.CreateMap<Stop, StopViewModel>().ReverseMap();
            });

            app.UseMvc(config =>
            {
                config.MapRoute(
                  name: "Default",
                  template: "{controller}/{action}/{id?}",
                  defaults: new { controller = "App", action = "Index" }
                  );
            });

            await seeder.EnsureSeedDataAsync();
        }
Esempio n. 7
0
        public void Configure(IApplicationBuilder app, WorldContextSeedData seeder,ILoggerFactory loggerFactory)
        {
            loggerFactory.AddDebug(LogLevel.Warning);

              app.UseStaticFiles();

              app.UseMvc(config =>
              {
            config.MapRoute(
            name: "Default",
            template: "{controller}/{action}/{id?}",
            defaults: new { controller = "App", action = "Index" }
            );
              });

              // Add the platform handler to the request pipeline.
              //app.UseIISPlatformHandler();

              //app.Run(async (context) =>
              //{
              //    await context.Response.WriteAsync("Hello World!");
              //});
              seeder.EnsureSeedData();
        }
Esempio n. 8
0
        /// <summary>
        /// For more details see the John's blog at
        /// http://wildermuth.com/2015/3/2/A_Look_at_ASP_NET_5_Part_2_-_Startup
        ///
        /// VERY IMPORTANT: the sequential order of Use directive matters!!!
        /// </summary>
        /// <param name="app"></param>
        /// <param name="loggerFactory"></param>
        /// <param name="seeder"></param>
        public async Task ConfigureAsync(
            IApplicationBuilder app,
            ILoggerFactory loggerFactory,
            WorldContextSeedData seeder)
        {
            // we have to choose: logging to console of debug window
            // or we could our own logging provider
            // here, we will add the debug window
            loggerFactory.AddDebug(LogLevel.Warning);

            app.UseStaticFiles();

            app.UseIdentity();

            // AutoMapper with the ReverseMap because
            // we have to be able to map in both directions
            Mapper.Initialize(config =>
            {
                config.CreateMap<Trip, TripViewModel>().ReverseMap();
                config.CreateMap<Stop, StopViewModel>().ReverseMap();
            });

            app.UseMvc(config =>
            {
                config.MapRoute(
                    name: "Default",
                    // in our case we have AppController.Index()
                    // but no 'id', so it will not be looking
                    // for the parameter of the Index method
                    template: "{controller}/{action}/{id?}",
                    // basically we are telling here that // localhost:8000
                    // should be same as localhost:8000/app/index.html
                    defaults: new { controller = "App", action = "Index" }
                );
            });

            // we want to inject it here because its constructor
            // has access to the DbContext and the necessary configuration information
            await seeder.EnsureSeedDataAsync();
        }
Esempio n. 9
0
 /// <summary>
 /// This is the entry point of the app, just a void method
 /// that calls the async ConfigureAsync method
 /// </summary>
 /// <param name="app"></param>
 /// <param name="loggerFactory"></param>
 /// <param name="seeder"></param>
 public void Configure(
     IApplicationBuilder app,
     ILoggerFactory loggerFactory,
     WorldContextSeedData seeder)
 {
     ConfigureAsync(app, loggerFactory, seeder).Wait();
 }
Esempio n. 10
0
        //Publish using DNU commands - without RUNTIMES
        //TheWorld\src\TheWorld>dnu publish -o D:\Test\TheWorldDnu

        //Publish using DNU commands - with specific RUNTIMES
        //TheWorld\src\TheWorld>dnu publish -o D:\Test\TheWorldDnu --runtime dnx-clr-win-x64.1.0.0-rc1-update1

        //use Postman app for webapi testing getpostman.com
        //http://www.johnpapa.net/get-up-and-running-with-node-and-visual-studio/
        //http://maxtoroq.github.io/2014/02/using-razor-and-xslt-in-same-project.html
        //https://docs.asp.net/en/latest/fundamentals/static-files.html
        //https://azure.microsoft.com/en-us/documentation/articles/web-sites-create-web-app-using-vscode/
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        /// public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)       

        //public void Configure(IApplicationBuilder app)
        //public void Configure(IApplicationBuilder app, WorldContextSeedData seeder, ILoggerFactory loggerFactory, IHostingEnvironment env)
        public async void Configure(IApplicationBuilder app, WorldContextSeedData seeder, ILoggerFactory loggerFactory, IHostingEnvironment env)
        {

            //token test 1
            //"Microsoft.AspNet.Server.WebListener": "1.0.0-rc1-final",
            //"Microsoft.AspNet.Authentication.JwtBearer": "1.0.0-rc1-final",
            //"AspNet.Security.OpenIdConnect.Server": "1.0.0-beta4"

            // Add a new middleware validating access tokens issued by the server.
            //app.UseJwtBearerAuthentication(options =>
            //{                
            //    options.AutomaticAuthenticate = true;
            //    options.Audience = "resource_server_1";
            //    options.Authority = "http://localhost:50000/";
            //    options.RequireHttpsMetadata = false;
            //});

            //token test 1
            // Add a new middleware issuing tokens.
            //app.UseOpenIdConnectServer(options =>
            //{
            //    options.AllowInsecureHttp = true;
            //    options.AuthorizationEndpointPath = PathString.Empty;
            //    options.TokenEndpointPath = "/connect/token";
            //    options.Provider = new AuthorizationProvider();
            //});

            //token 2 begin
            // Register a simple error handler to catch token expiries and change them to a 401, 
            // and return all other errors as a 500. This should almost certainly be improved for
            // a real application.
            /*
            app.UseIISPlatformHandler();
            app.UseExceptionHandler(appBuilder =>
            {
                appBuilder.Use(async (context, next) =>
                {
                    var error = context.Features[typeof(IExceptionHandlerFeature)] as IExceptionHandlerFeature;
                    // This should be much more intelligent - at the moment only expired 
                    // security tokens are caught - might be worth checking other possible 
                    // exceptions such as an invalid signature.
                    if (error != null && error.Error is SecurityTokenExpiredException)
                    {
                        context.Response.StatusCode = 401;
                        // What you choose to return here is up to you, in this case a simple 
                        // bit of JSON to say you're no longer authenticated.
                        context.Response.ContentType = "application/json";
                        await context.Response.WriteAsync(
                            JsonConvert.SerializeObject(
                                new { authenticated = false, tokenExpired = true }));
                    }
                    else if (error != null && error.Error != null)
                    {
                        context.Response.StatusCode = 500;
                        context.Response.ContentType = "application/json";
                        // TODO: Shouldn't pass the exception message straight out, change this.
                        await context.Response.WriteAsync(
                            JsonConvert.SerializeObject
                            (new { success = false, error = error.Error.Message }));
                    }
                    // We're not trying to handle anything else so just let the default 
                    // handler handle.
                    else await next();
                });
            });

            app.UseJwtBearerAuthentication(options =>
            {
                // Basic settings - signing key to validate with, audience and issuer.
                options.TokenValidationParameters.IssuerSigningKey = key;
                options.TokenValidationParameters.ValidAudience = tokenOptions.Audience;
                options.TokenValidationParameters.ValidIssuer = tokenOptions.Issuer;

                // When receiving a token, check that we've signed it.
                options.TokenValidationParameters.ValidateSignature = true;

                // When receiving a token, check that it is still valid.
                options.TokenValidationParameters.ValidateLifetime = true;

                // This defines the maximum allowable clock skew - i.e. provides a tolerance on the token expiry time 
                // when validating the lifetime. As we're creating the tokens locally and validating them on the same 
                // machines which should have synchronised time, this can be set to zero. Where external tokens are
                // used, some leeway here could be useful.
                options.TokenValidationParameters.ClockSkew = TimeSpan.FromMinutes(0);                
            });
            //token 2 end
            */
            
            if (env.IsDevelopment())
            {
                //loggerFactory.AddProvider(new CustomLogger());
                loggerFactory.AddDebug(LogLevel.Information);
                app.UseDeveloperExceptionPage();
                app.UseRuntimeInfoPage();
            }
            else
            {                
                loggerFactory.AddDebug(LogLevel.Error);
                //app.UseExceptionHandler("App/Error");
                app.UseDeveloperExceptionPage();
            }            

            //app.UseDefaultFiles();
            app.UseStaticFiles();

            app.UseIdentity();

            Mapper.Initialize(config=>
            {
                config.CreateMap<Trip, TripViewModel>().ReverseMap();
                config.CreateMap<Stop, StopViewModel>().ReverseMap();
            });

            /*
#if DEBUG
            if (env.IsDevelopment())
            {
                //app.UseExceptionHandler(...)
                app.UseDeveloperExceptionPage();

                // Add the runtime information page that can be used by developers
                // to see what packages are used by the application
                // default path is: /runtimeinfo
                app.UseRuntimeInfoPage();
            }
#else
         
#endif
            */

            app.UseMvc(config =>
            {
                config.MapRoute(
                  name: "Default",
                  template: "{controller}/{action}/{id?}",
                  defaults: new { controller = "App", action = "Index" }
                  );

                //config.MapRoute(
                //  name: "App",
                //  template: "App/{action}/{id?}",
                //  defaults: new {controller="app", action = "Index" }
                //  );

            });

            /*
            app.Run(async (context) =>
            {
                //await context.Response.WriteAsync("Hello World!");
                await context.Response.WriteAsync($"Hello World: {context.Request.Path}");
            });
            */

            //seeder.EnsureSeedData();
            await seeder.EnsureSeedDataAsync();
        }
Esempio n. 11
0
        public async void Configure(IApplicationBuilder app, WorldContextSeedData seeder, ILoggerFactory loggerFactory)
        {
            //app.UseIISPlatformHandler();

            // Enable using Static files
            app.UseStaticFiles();

            // Use Identity. The order MATTERS! UseIdentity must before UseMvc
            app.UseIdentity();


            // turn on mvc
            app.UseMvc(config =>
            {
                // Add Route
                config.MapRoute(
                    name: "Default",
                    template: "{controller}/{action}/{id?}",
                    defaults: new { controller = "App", action = "Index" }
                    );
            });

            // run the seed.
            await seeder.EnsureSeedDataAsync();

            // Enable logging.
            loggerFactory.AddDebug(LogLevel.Warning);

            // Configure AutoMapper
            Mapper.Initialize(config =>
            {
                config.CreateMap<Trip, TripViewModel>().ReverseMap();
                config.CreateMap<Stop, StopViewModel>().ReverseMap();
            });
        }
Esempio n. 12
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public async void Configure(IApplicationBuilder app, WorldContextSeedData seeder, ILoggerFactory loggerFactory)
        {
            loggerFactory.AddDebug(LogLevel.Warning);

            app.UseStaticFiles();

            // The order sequence of these runtime method MATTER. 
            // First, the app checks for static files. Next, it checks for
            // identity and MVC.
            app.UseIdentity();

            // This allows for all the configuration among types.
            Mapper.Initialize(config =>
            {
                // I want to go from Trip to VM and do the reverse as well.
                config.CreateMap<Trip, TripViewModel>().ReverseMap();

                config.CreateMap<Stop, StopViewModel>().ReverseMap();
            });

            app.UseMvc(config =>
            {
                config.MapRoute(
                    name: "Default",
                    template: "{controller}/{action}/{id?}",
                    defaults: new { controller = "App", action = "Index" }
                );
            });

            await seeder.EnsureSeedDataAsync();
        }
Esempio n. 13
0
    // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
    public async void Configure(IApplicationBuilder app,
      WorldContextSeedData seeder,
      ILoggerFactory loggerFactory,
      IHostingEnvironment env)
    {
            // app.UseSession
      if (env.IsDevelopment())
      {
        loggerFactory.AddDebug(LogLevel.Information);
        app.UseDeveloperExceptionPage();
      }
      else
      {
        loggerFactory.AddDebug(LogLevel.Debug);
        app.UseDeveloperExceptionPage();
      }
      app.UseStaticFiles();
      app.UseIdentity();
      Mapper.Initialize(config =>
      {
        config.CreateMap<Trip, TripViewModel>().ReverseMap();
        config.CreateMap<Stop, StopViewModel>().ReverseMap();

          // 
          // more complicated would be
          // config.CreateMap<Trip, TripViewModel>().ForMember(dest => dest.memberName, opt => opt.MapFrom(src = src.Member.MemberName)
          // see docs

      });

      app.UseMvc(config =>
      {
        config.MapRoute(
          name: "Default",
          template: "{controller}/{action}/{id?}",
          defaults: new { controller = "App", action = "Index" }
          );
      });

      await seeder.EnsureSeedDataAsync();
    }
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public async void Configure(IApplicationBuilder app, WorldContextSeedData seeder, ILoggerFactory loggerFactory)
        {
            //app.Run(async (context) =>
            //{
            //    await context.Response.WriteAsync("Hello World!");
            //});

            //app.UseDefaultFiles(); // Use index.html as the root (/) // do not need this with mvc 6
            loggerFactory.AddDebug(LogLevel.Information);

            app.UseStaticFiles(); // Tell IIS to use the static files found in wwwroot

            app.UseIdentity();

            Mapper.Initialize(config =>
            {
                config.CreateMap<Trip, TripViewModel>().ReverseMap(); // Reverse map: I want to go from trip to tripviewmodel as well as the oposit
                config.CreateMap<Stop, StopViewModel>().ReverseMap();
            });

            app.UseMvc(config =>
            {
                config.MapRoute(
                    name: "Default",
                    template: "{controller}/{action}/{id?}",
                    defaults: new { controller = "App", action = "Index" }
                    );
            });

            await seeder.EnsureSeedData();
        }