本文整理汇总了C#中IApplicationBuilder.UseMvc方法的典型用法代码示例。如果您正苦于以下问题:C# IApplicationBuilder.UseMvc方法的具体用法?C# IApplicationBuilder.UseMvc怎么用?C# IApplicationBuilder.UseMvc使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IApplicationBuilder
的用法示例。
在下文中一共展示了IApplicationBuilder.UseMvc方法的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
public void Configure(IApplicationBuilder app)
{
app.UseMvc(routes => {
routes.MapRoute(
"Default",
"{action}",
new { controller = "Home", action = "Index", id = "" }
);
});
app.UseMvc(routes => {
routes.MapRoute(
"Default2",
"home/{hash}",
new { controller = "Home", action = "Index", id = "" }
);
});
app.UseMvc(routes => {
routes.MapRoute(
"Default3",
"exchange/upload",
new { controller = "Exchange", action="Upload" }
);
});
app.UseMvc(routes => {
routes.MapRoute(
"Default3",
"exchange/download/{serverFileName}",
new { controller = "Exchange", action = "Download" }
);
});
}
示例3: Configure
// Configure is called after ConfigureServices is called.
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
loggerFactory.MinimumLevel = LogLevel.Information;
// Add the following to the request pipeline only in development environment.
if (env.IsDevelopment())
{
app.UseBrowserLink();
//app.UseErrorPage(ErrorPageOptions.ShowAll);
}
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 MVC to the request pipeline.
app.UseMvc(routes =>
{
});
app.UseMvc();
}
示例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.UseStaticFiles();
app.UseStaticFiles(new StaticFileOptions()
{
FileProvider = new PhysicalFileProvider(
Path.Combine(Directory.GetCurrentDirectory(), @"Images")),
RequestPath = new PathString("/Images")
});
// Add MVC to the request pipeline.
app.UseMvc(routes =>
{
routes.MapRoute(name: "areaRoute",
template: "{area}/{controller}/{action}",
defaults: new { area = "v2", controller = "Images", action = "Index" });
routes.MapRoute(
name: "default",
template: "{controller}/{action}/{id?}",
defaults: new { controller = "Home", action = "Index" });
});
// Add the following route for porting Web API 2 controllers.
// routes.MapWebApiRoute("DefaultApi", "api/{controller}/{id?}");
app.UseCors("default");
app.UseMvc();
}
示例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.UseBrowserLink();
app.UseDeveloperExceptionPage();
//app.UseDatabaseErrorPage();
}
app.UseIISPlatformHandler();
app.UseStaticFiles();
app.UseMvc(routes => routes.MapRoute(
name: "default",
template: "{controller}/{action}/{id?}",
defaults: new { controller = "Home", action = "Index" }
).MapRoute(
name: "language",
template: "{language}/{controller}/{action}/{id?}",
defaults: new { controller = "Home", action = "Index" }
));
app.UseMvc(routes =>
routes.MapRoute(
name: "default",
template: "{controller}/{action}/{id?}",
defaults: new { controller = "Home", action = "Index" })
.MapRoute(
name: "language",
template: "{language}/{controller}/{action}/{id?}",
defaults: new { controller = "Home", action = "Index" },
constraints: new { language = @"(en)|(de)" })
.MapRoute(
name: "multipleparameters",
template: "{controller}/{action}/{x}/{y}",
defaults: new { controller = "Home", action = "Add" },
constraints: new { x = @"\d", y = @"\d" }
));
app.UseMvc(routes => routes.MapRoute(
name: "language",
template: "{language}/{controller}/{action}/{id?}",
defaults: new { controller = "Home", action = "Index" },
constraints: new { language = @"(en)|(de)" }
));
app.UseMvcWithDefaultRoute();
}
示例6: 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.UseBrowserLink();
}
else
{
app.UseExceptionHandler("/Home/Error");
}
app.UseStaticFiles();
#if First
#region snippet1
app.UseMvc(routes =>
{
routes.MapAreaRoute("blog_route", "Blog",
"Manage/{controller}/{action}/{id?}");
routes.MapRoute("default_route", "{controller}/{action}/{id?}");
});
#endregion
#else
#region snippet2
app.UseMvc(routes =>
{
routes.MapRoute("blog_route", "Manage/{controller}/{action}/{id?}",
defaults: new { area = "Blog" }, constraints: new { area = "Blog" });
routes.MapRoute("default_route", "{controller}/{action}/{id?}");
});
#endregion
#endif
#if Third
#region snippet3
app.UseMvc(routes =>
{
routes.MapAreaRoute("duck_route", "Duck",
"Manage/{controller}/{action}/{id?}");
routes.MapRoute("default", "Manage/{controller=Home}/{action=Index}/{id?}");
});
#endregion
#endif
}
示例7: Configure
public void Configure(IApplicationBuilder app)
{
// Request pipeline
app.UseWebSockets();
app.Use(HandleWebSocketsAsync);
app.UseMvc();
// Initialization
Task.Run(async () =>
{
await InitializeDatabaseAsync();
await InitializeServiceBrokerAsync(app.ApplicationServices);
})
.Wait();
// Background tasks
Task.Run(async () =>
{
await ProcessMessagesAsync(app.ApplicationServices);
});
}
示例8: Configure
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, BeaconsContextSeedData seeder)
{
app.UseStaticFiles();
app.UseDeveloperExceptionPage();
Mapper.Initialize(config =>
{
config.CreateMap<Beacon, BeaconViewModel>().ReverseMap();
config.CreateMap<Log, LogViewModel>().ReverseMap();
});
app.UseIISPlatformHandler();
app.UseMvc(config =>
{
config.MapRoute(
name: "Default",
template: "{controller}/{action}/{id?}",
defaults: new { controller = "App", action ="Index"}
);
});
seeder.EnsureSeedData();
}
示例9: Configure
public void Configure(IApplicationBuilder app)
{
app.UseIISPlatformHandler();
app.UseMvc(routes =>
routes.MapRoute("default", "{controller}/{action}", new { controller = "home", action = "index" }));
}
示例10: Configure
// Configure is called after ConfigureServices is called.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
// Add MVC to the request pipeline.
app.UseMvc();
// Add the following route for porting Web API 2 controllers.
// routes.MapWebApiRoute("DefaultApi", "api/{controller}/{id?}");
}
示例11: Configure
public void Configure(IApplicationBuilder app)
{
app.UseCultureReplacer();
app.UseErrorReporter();
app.UseMvc(routes =>
{
routes.MapRoute(
name: "isbn10",
template: "book/{action}/{isbnNumber:IsbnDigitScheme10(true)}",
defaults: new { controller = "InlineConstraints_Isbn10" });
routes.MapRoute("StoreId",
"store/{action}/{id:guid?}",
defaults: new { controller = "InlineConstraints_Store" });
routes.MapRoute("StoreLocation",
"store/{action}/{location:minlength(3):maxlength(10)}",
defaults: new { controller = "InlineConstraints_Store" },
constraints: new { location = new AlphaRouteConstraint() });
// Used by tests for the 'exists' constraint.
routes.MapRoute("areaExists-area", "area-exists/{area:exists}/{controller=Home}/{action=Index}");
routes.MapRoute("areaExists", "area-exists/{controller=Home}/{action=Index}");
routes.MapRoute("areaWithoutExists-area", "area-withoutexists/{area}/{controller=Home}/{action=Index}");
routes.MapRoute("areaWithoutExists", "area-withoutexists/{controller=Home}/{action=Index}");
});
}
示例12: 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();
// Add external authentication middleware below. To configure them please see http://go.microsoft.com/fwlink/?LinkID=532715
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
}
示例13: 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?}");
});
}
示例14: Configure
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, IConfigurationRoot configuration)
{
loggerFactory.AddConsole(configuration.GetSection("Logging"));
loggerFactory.AddDebug();
// 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())
{
using (var db = serviceScope.ServiceProvider.GetService<ApplicationDbContext>())
{
db.Database.EnsureCreated();
db.Database.Migrate();
}
}
}
catch (Exception exception)
{
}
app.UseCors("AllowAllOrigins"); // TODO: allow collection of allowed origins per client
app.UseIISPlatformHandler();
app.UseStaticFiles();
app.UseMvc();
}
示例15: 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.UseIISPlatformHandler();
app.UseApplicationInsightsRequestTelemetry();
app.UseApplicationInsightsExceptionTelemetry();
app.UseStaticFiles();
app.Use(async (context, next) =>
{
context.Response.Headers.Add("Access-Control-Allow-Origin", "*");
context.Response.Headers.Add("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS");
context.Response.Headers.Add("Access-Control-Allow-Headers", new[] { "Content-Type, x-xsrf-token" });
if (context.Request.Method == "OPTIONS")
{
context.Response.StatusCode = 200;
}
else
{
await next();
}
});
app.UseMvc();
SampleData.Initialize(app.ApplicationServices);
}