本文整理汇总了C#中IApplicationBuilder.EnsureSampleData方法的典型用法代码示例。如果您正苦于以下问题:C# IApplicationBuilder.EnsureSampleData方法的具体用法?C# IApplicationBuilder.EnsureSampleData怎么用?C# IApplicationBuilder.EnsureSampleData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IApplicationBuilder
的用法示例。
在下文中一共展示了IApplicationBuilder.EnsureSampleData方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Configure
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
loggerFactory.AddDebug();
app.UseApplicationInsightsRequestTelemetry();
if (env.IsDevelopment()) {
app.UseDeveloperExceptionPage();
app.UseDatabaseErrorPage();
app.UseBrowserLink();
app.EnsureSampleData(); // TODO: Only in production
} else {
app.UseExceptionHandler("/error");
try {
using (var serviceScope = app.ApplicationServices.GetRequiredService<IServiceScopeFactory>().CreateScope()) {
serviceScope.ServiceProvider.GetService<ApplicationDbContext>().Database.Migrate();
}
app.EnsureSampleData();
} catch {
// TODO: Should this be handled? Snippet copy-pasted from Microsoft example
// http://docs.asp.net/en/latest/conceptual-overview/understanding-aspnet5-apps.html
}
}
app.UseApplicationInsightsExceptionTelemetry();
app.UseStaticFiles();
// TODO: Why does Core 1.0 throw an exception when this worked in RC1+RC2?
// app.UseStripWhitespace();
app.UseSession();
app.UseMvc(routes => {
routes.MapRoute("default", "{controller=Blog}/{action=Index}/{id?}");
});
}
示例2: Configure
// Configure is called after ConfigureServices is called.
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerfactory)
{
// Configure the HTTP request pipeline.
// Add the console logger.
loggerfactory.AddConsole(minLevel: LogLevel.Warning);
loggerfactory.AddProvider(new SqlLoggerProvider());
// Add the following to the request pipeline only in development environment.
if (env.IsEnvironment("Development"))
{
app.UseBrowserLink();
app.UseErrorPage();
app.UseDatabaseErrorPage(DatabaseErrorPageOptions.ShowAll);
app.EnsureMigrationsApplied();
app.EnsureSampleData();
}
else
{
// Add Error handling middleware which catches all application specific errors and
// sends the request to the following path or controller action.
app.UseErrorHandler("/Home/Error");
}
// Add static files to the request pipeline.
app.UseStaticFiles();
// Add cookie-based authentication to the request pipeline.
app.UseIdentity();
if (_useFacebookAuth)
{
app.UseFacebookAuthentication();
}
if (_useGoogleAuth)
{
app.UseGoogleAuthentication();
}
app.EnsureRolesCreated();
// Add MVC to the request pipeline.
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller}/{action}/{id?}",
defaults: new { controller = "Home", action = "Index" });
// Uncomment the following line to add a route for porting Web API 2 controllers.
// routes.MapWebApiRoute("DefaultApi", "api/{controller}/{id?}");
});
}
示例3: Configure
public void Configure(IApplicationBuilder app)
{
app.UseDeveloperExceptionPage();
app.UseMvc(routes =>
{
routes.MapRoute(name: "default", template: "{controller=Home}/{action=Index}");
});
app.EnsureMigrationsApplied();
app.EnsureSampleData();
}
示例4: Configure
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
loggerFactory.AddConsole(LogLevel.None);
app.UseDatabaseErrorPage();
app.UseDeveloperExceptionPage();
app.UseRequestLocalization(new RequestLocalizationOptions()
{
SupportedCultures = new List<CultureInfo>
{
new CultureInfo("en-US")
},
SupportedUICultures = new List<CultureInfo>
{
new CultureInfo("en-US")
},
}, new RequestCulture(new CultureInfo("nl-NL")));
app.UseIISPlatformHandler(options => options.AuthenticationDescriptions.Clear());
app.UseStaticFiles();
app.UseIdentity();
app.EnsureSampleData().Wait();
var onRemoteError = new OAuthEvents()
{
OnRemoteError = ctx =>
{
ctx.Response.Redirect("/Account/ExternalLoginCallback?RemoteError=" + UrlEncoder.Default.UrlEncode(ctx.Error.Message));
ctx.HandleResponse();
return Task.FromResult(0);
}
};
// To configure external authentication please see http://go.microsoft.com/fwlink/?LinkID=532715
if (_startup.Configuration["Authentication:Google:ClientId"] != null)
{
app.UseFacebookAuthentication(options =>
{
options.AppId = _startup.Configuration["Authentication:Facebook:AppId"];
options.AppSecret = _startup.Configuration["Authentication:Facebook:AppSecret"];
options.DisplayName = "facebook";
options.Events = onRemoteError;
});
app.UseGoogleAuthentication(options =>
{
options.ClientId = _startup.Configuration["Authentication:Google:ClientId"];
options.ClientSecret = _startup.Configuration["Authentication:Google:ClientSecret"];
options.DisplayName = "google plus";
options.Events = onRemoteError;
});
}
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
}
示例5: Configure
// 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)
{
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
loggerFactory.AddDebug();
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
app.UseDatabaseErrorPage();
app.UseBrowserLink();
// prepopulates database
app.EnsureSampleData();
}
else
{
app.UseExceptionHandler("/Home/Error");
// For more details on creating database during deployment see http://go.microsoft.com/fwlink/?LinkID=615859
//try
//{
// using (var serviceScope = app.ApplicationServices.GetRequiredService<IServiceScopeFactory>()
// .CreateScope())
// {
// serviceScope.ServiceProvider.GetService<ApplicationDbContext>()
// .Database.Migrate();
// }
//}
//catch
//{
//}
}
//app.UseReact(config =>
//{
// config
// .SetReuseJavaScriptEngines(true)
// .SetLoadBabel(false)
// .AddScriptWithoutTransform("~/js/dist/serverBundle.js");
//});
app.UseStaticFiles();
app.UseIdentity();
// To configure external authentication please see http://go.microsoft.com/fwlink/?LinkID=532715
app.UseMvc(routes =>
{
routes.MapRoute(
"default",
"{controller=Home}/{action=Index}/{id?}");
});
}
示例6: Configure
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
loggerFactory.AddProvider(new SqlLoggerProvider());
loggerFactory.AddDebug();
if (env.IsDevelopment())
{
app.UseBrowserLink();
app.UseDeveloperExceptionPage();
app.UseDatabaseErrorPage();
using (var serviceScope = app.ApplicationServices.GetRequiredService<IServiceScopeFactory>()
.CreateScope())
{
serviceScope.ServiceProvider.GetService<UnicornStoreContext>().Database.Migrate();
serviceScope.ServiceProvider.GetService<ApplicationDbContext>().Database.Migrate();
}
app.EnsureSampleData();
}
else
{
app.UseExceptionHandler("/Home/Error");
}
app.UseIISPlatformHandler(options => options.AuthenticationDescriptions.Clear());
app.UseStaticFiles();
app.UseIdentity();
app.EnsureRolesCreated();
// See comments in config.json for info on enabling Facebook auth
var facebookId = Configuration["Auth:Facebook:AppId"];
var facebookSecret = Configuration["Auth:Facebook:AppSecret"];
if (!string.IsNullOrWhiteSpace(facebookId) && !string.IsNullOrWhiteSpace(facebookSecret))
{
app.UseFacebookAuthentication(options =>
{
options.AppId = facebookId;
options.AppSecret = facebookSecret;
});
}
// See comments in config.json for info on enabling Google auth
var googleId = Configuration["Auth:Google:ClientId"];
var googleSecret = Configuration["Auth:Google:ClientSecret"];
if (!string.IsNullOrWhiteSpace(googleId) && !string.IsNullOrWhiteSpace(googleSecret))
{
app.UseGoogleAuthentication(options =>
{
options.ClientId = googleId;
options.ClientSecret = googleSecret;
});
}
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
}