本文整理汇总了C#中IHostingEnvironment.IsDevelopment方法的典型用法代码示例。如果您正苦于以下问题:C# IHostingEnvironment.IsDevelopment方法的具体用法?C# IHostingEnvironment.IsDevelopment怎么用?C# IHostingEnvironment.IsDevelopment使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IHostingEnvironment
的用法示例。
在下文中一共展示了IHostingEnvironment.IsDevelopment方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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();
_logger = loggerFactory.CreateLogger("Test");
_logger.LogInformation("Starting Jacks logging");
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseExceptionHandler("/Home/Error");
}
app.UseIISPlatformHandler();
app.UseStaticFiles();
app.UseSignalR2();
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
_dm = new DownloadManager(_logger, GlobalHost.ConnectionManager.GetHubContext<Scraper.Hubs.ChatHub>());
Console.CancelKeyPress += (s,e) => { _logger.LogInformation("CTRL+C detected - shutting down"); _dm.Stop(); };
}
示例2: 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();
}
else
{
app.UseExceptionHandler("/Home/Error");
}
app.UseStaticFiles();
app.UseIdentity();
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
if (env.IsDevelopment())
{
//SeedOfficers(app.ApplicationServices);
//HotFix_RevisedTime (app.ApplicationServices);
}
}
示例3: 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();
}
else
{
app.UseExceptionHandler("/Home/Error");
}
app.UseIISPlatformHandler();
if (env.IsDevelopment()) {
app.UseWebpackDevMiddleware(new WebpackDevMiddlewareOptions {
HotModuleReplacement = true
});
}
app.UseStaticFiles();
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
}
示例4: 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();
app.UseMiddleware<Middleware.FilterLinkProbes>();
if (env.IsDevelopment())
{
app.UseBrowserLink();
app.UseDeveloperExceptionPage();
}
app.UseIISPlatformHandler();
if (!env.IsDevelopment())
{
// This has to come after UseIISPlatformHandler(), otherwise
// the request context will always think it's HTTP
app.UseMiddleware<Middleware.EnforceHttps>();
}
app.UseStaticFiles();
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{action=Set}",
defaults: new {controller = "Home"});
});
}
示例5: Configure
public void Configure(IApplicationBuilder app, IHostingEnvironment environment, ILoggerFactory factory) {
factory.AddConsole();
factory.AddDebug();
app.UseIISPlatformHandler();
if (environment.IsDevelopment()) {
app.UseDeveloperExceptionPage();
}
app.UseDefaultFiles();
app.UseStaticFiles();
// Add a new middleware validating access tokens.
app.UseJwtBearerAuthentication(options => {
// Automatic authentication must be enabled
// for SignalR to receive the access token.
options.AutomaticAuthenticate = true;
// Automatically disable the HTTPS requirement for development scenarios.
options.RequireHttpsMetadata = !environment.IsDevelopment();
// Note: the audience must correspond to the address of the SignalR server.
options.Audience = "http://localhost:5000/";
// Note: the authority must match the address of the identity server.
options.Authority = "http://localhost:5000/";
options.Events = new JwtBearerEvents {
// Note: for SignalR connections, the default Authorization header does not work,
// because the WebSockets JS API doesn't allow setting custom parameters.
// To work around this limitation, the access token is retrieved from the query string.
OnReceivingToken = context => {
// Note: when the token is missing from the query string,
// context.Token is null and the JWT bearer middleware will
// automatically try to retrieve it from the Authorization header.
context.Token = context.Request.Query["access_token"];
return Task.FromResult(0);
}
};
});
app.UseWebSockets();
app.UseSignalR<SimpleConnection>("/signalr");
// Add a new middleware issuing access tokens.
app.UseOpenIdConnectServer(options => {
options.Provider = new AuthenticationProvider();
});
}
示例6: Startup
public Startup(IHostingEnvironment env)
{
_isDevEnvironment = env.IsDevelopment();
var builder = new ConfigurationBuilder()
.AddJsonFile("Haufwerk.json")
.AddEnvironmentVariables("Haufwerk:");
if (env.IsDevelopment())
{
// This will push telemetry data through Application Insights pipeline faster, allowing you to view results immediately.
builder.AddApplicationInsightsSettings(true);
}
Configuration = builder.Build();
}
示例7: Configure
// Configure is called after ConfigureServices is called.
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
loggerFactory.AddDebug();
// Add the following to the request pipeline only in development environment.
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
// Add Error handling middleware which catches all application specific errors and
// send the request to the following path or controller action.
app.UseExceptionHandler("/Home/Error");
}
// Add the platform handler to the request pipeline.
app.UseIISPlatformHandler();
// Add static files to the request pipeline.
app.UseStaticFiles();
// Add MVC to the request pipeline.
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
routes.MapRoute("DefaultApi", "api/{controller}/{id?}");
});
}
示例8: Startup
public Startup(
IHostingEnvironment env,
IApplicationEnvironment appEnv)
{
_env = env;
// Setup configuration sources.
var builder = new ConfigurationBuilder()
.SetBasePath(appEnv.ApplicationBasePath)
// standard config file
.AddJsonFile("config.json")
// environment specific config.<environment>.json file
.AddJsonFile($"config.{env.EnvironmentName}.json", true /* override if exists */)
// standard Windows environment variables
.AddEnvironmentVariables();
if (env.IsDevelopment())
{
// this one adds not using directive to keep it secret, only a dnx reference
// the focus is not on Secrets but on User, so these are User specific settings
// we can also make it available only for developers
builder.AddUserSecrets();
}
Configuration = builder.Build();
}
示例9: Configure
// Configure is called after ConfigureServices is called.
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
if(env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
loggerFactory
.AddConsole(Configuration.GetSection("Logging"))
.AddDebug();
// Use the Default files ['index.html', 'index.htm', 'default.html', 'default.htm']
app.UseDefaultFiles()
.UseStaticFiles()
.UseIISPlatformHandler()
.UseMvc();
// Setup a generic Quotes API EndPoint
app.Map("/api/quotes", (config) =>
{
app.Run(async context =>
{
var quotes = "{ \"quotes\":" +
" [ { \"quote\": \"Duct tape is like the force. It has a light side, a dark side, and it holds the universe together.\", \"author\":\"Oprah Winfrey\"} ]" +
"}";
context.Response.ContentLength = quotes.Length;
context.Response.ContentType = "application/json";
await context.Response.WriteAsync(quotes);
});
});
}
示例10: Configure
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
loggerFactory.AddDebug();
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseExceptionHandler("/Home/Error");
}
app.UseStaticFiles();
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationScheme = Constants.MiddlewareScheme,
LoginPath = new PathString("/Account/Login/"),
AccessDeniedPath = new PathString("/Account/Forbidden/"),
AutomaticAuthenticate = true,
AutomaticChallenge = true
});
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
}
示例11: Startup
public Startup(IHostingEnvironment env, IApplicationEnvironment appEnvironment)
{
_appEnvironment = appEnvironment;
_hostingEnvironment = env;
var RollingPath = Path.Combine(appEnvironment.ApplicationBasePath, "logs/myapp-{Date}.txt");
Log.Logger = new LoggerConfiguration()
.WriteTo.RollingFile(RollingPath)
.CreateLogger();
Log.Information("Ah, there you are!");
// Set up configuration sources.
var builder = new ConfigurationBuilder()
.AddJsonFile("appsettings.json")
.AddJsonFile("appsettings-filters.json")
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true);
if (env.IsDevelopment())
{
// For more details on using the user secret store see http://go.microsoft.com/fwlink/?LinkID=532709
builder.AddUserSecrets();
}
builder.AddEnvironmentVariables();
Configuration = builder.Build();
// Initialize the global configuration static
GlobalConfigurationRoot.Configuration = Configuration;
}
示例12: ConfigureCookies
/// <summary>
/// Configure default cookie settings for the application which are more secure by default.
/// </summary>
/// <param name="application">The application.</param>
/// <param name="environment">The environment the application is running under. This can be Development,
/// Staging or Production by default.</param>
private static void ConfigureCookies(
IApplicationBuilder application,
IHostingEnvironment environment)
{
// In the Development environment, different ports are being used for HTTP and HTTPS. The
// RequireHttpsAttribute expects to use the default ports 80 for HTTP and port 443 for HTTPS and simply
// adds an 's' onto 'http'. Therefore, we don't require secure cookies in the development environment.
SecurePolicy securePolicy;
if (environment.IsDevelopment())
{
// Ensure that the cookie can only be transported over the same scheme as the request.
securePolicy = SecurePolicy.SameAsRequest;
}
else
{
// Ensure that the cookie can only be transported over HTTPS.
securePolicy = SecurePolicy.Always;
}
application.UseCookiePolicy(
new CookiePolicyOptions()
{
// Ensure that external script cannot access the cookie.
HttpOnly = HttpOnlyPolicy.Always,
Secure = securePolicy
});
}
示例13: 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)
{
SuperDataBase.Configure(env, app.ApplicationServices.GetService<IOptions<AppConfig>>());
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
loggerFactory.AddDebug();
if (env.IsDevelopment())
{
app.UseBrowserLink();
app.UseDeveloperExceptionPage();
}
else
{
app.UseExceptionHandler("/Home/Error");
}
app.UseIISPlatformHandler();
app.UseStaticFiles();
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
}
示例14: Configure
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
loggerFactory.MinimumLevel = LogLevel.Information;
loggerFactory.AddConsole();
loggerFactory.AddDebug();
// Configure the HTTP request pipeline.
// Add the following to the request pipeline only in development environment.
if (env.IsDevelopment())
{
app.UseBrowserLink();
}
// Add the platform handler to the request pipeline.
app.UseIISPlatformHandler();
// Add static files to the request pipeline.
app.UseStaticFiles();
// Add MVC to the request pipeline.
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
}
示例15: Configure
public void Configure(IApplicationBuilder app,
IHostingEnvironment env,
ILoggerFactory loggerFactory)
{
Log.Logger =
new LoggerConfiguration()
.MinimumLevel.Error()
.WriteTo.TextWriter(System.Console.Out)
.WriteTo.RollingFile(@"C:\temp\TSWebLog-{Date}.txt")
.CreateLogger();
loggerFactory.AddSerilog();
app.UseStaticFiles();
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller}/{action}/{id?}",
defaults: new { controller = "Home", action = "Index" });
});
}