asp.net 5
来源:互联网 发布:分布式 java 编辑:程序博客网 时间:2024/05/16 15:07
相关学习地址:http://www.cnblogs.com/TomXu/p/4496545.html
以下计算视图执行的时间
using System;using System.Collections.Generic;using System.Diagnostics;using System.Linq;using System.Threading.Tasks;using Microsoft.AspNet.Authentication.Facebook;using Microsoft.AspNet.Authentication.Google;using Microsoft.AspNet.Authentication.MicrosoftAccount;using Microsoft.AspNet.Authentication.Twitter;using Microsoft.AspNet.Builder;using Microsoft.AspNet.Diagnostics;using Microsoft.AspNet.Diagnostics.Entity;using Microsoft.AspNet.Hosting;using Microsoft.AspNet.Http;using Microsoft.AspNet.Identity;using Microsoft.AspNet.Identity.EntityFramework;using Microsoft.AspNet.Routing;using Microsoft.Data.Entity;using Microsoft.Framework.Configuration;using Microsoft.Framework.DependencyInjection;using Microsoft.Framework.Logging;using Microsoft.Framework.Logging.Console;using Microsoft.Framework.Runtime;using WebApplication2.Models;using WebApplication2.Services;namespace WebApplication2{ public class Startup { public Startup(IHostingEnvironment env, IApplicationEnvironment appEnv) { // Setup configuration sources. var builder = new ConfigurationBuilder(appEnv.ApplicationBasePath) .AddJsonFile("config.json") .AddJsonFile($"config.{env.EnvironmentName}.json", optional: true); if (env.IsDevelopment()) { // This reads the configuration keys from the secret store. // For more details on using the user secret store see http://go.microsoft.com/fwlink/?LinkID=532709 builder.AddUserSecrets(); } builder.AddEnvironmentVariables(); Configuration = builder.Build(); } public IConfiguration Configuration { get; set; } // This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { // Add Entity Framework services to the services container. services.AddEntityFramework() .AddSqlServer() .AddDbContext<ApplicationDbContext>(options => options.UseSqlServer(Configuration["Data:DefaultConnection:ConnectionString"])); // Add Identity services to the services container. services.AddIdentity<ApplicationUser, IdentityRole>() .AddEntityFrameworkStores<ApplicationDbContext>() .AddDefaultTokenProviders(); // Configure the options for the authentication middleware. // You can add options for Google, Twitter and other middleware as shown below. // For more information see http://go.microsoft.com/fwlink/?LinkID=532715 services.Configure<FacebookAuthenticationOptions>(options => { options.AppId = Configuration["Authentication:Facebook:AppId"]; options.AppSecret = Configuration["Authentication:Facebook:AppSecret"]; }); services.Configure<MicrosoftAccountAuthenticationOptions>(options => { options.ClientId = Configuration["Authentication:MicrosoftAccount:ClientId"]; options.ClientSecret = Configuration["Authentication:MicrosoftAccount:ClientSecret"]; }); // Add MVC services to the services container. services.AddMvc(); // Uncomment the following line to add Web API services which makes it easier to port Web API 2 controllers. // You will also need to add the Microsoft.AspNet.Mvc.WebApiCompatShim package to the 'dependencies' section of project.json. // services.AddWebApiConventions(); // Register application services. services.AddTransient<IEmailSender, AuthMessageSender>(); services.AddTransient<ISmsSender, AuthMessageSender>(); } // Configure is called after ConfigureServices is called. public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) { app.UseMiddleware<TimeRecorderMiddleware>(); loggerFactory.MinimumLevel = LogLevel.Information; loggerFactory.AddConsole(); // Configure the HTTP request pipeline. // Add the following to the request pipeline only in development environment. if (env.IsDevelopment()) { app.UseBrowserLink(); app.UseErrorPage(ErrorPageOptions.ShowAll); app.UseDatabaseErrorPage(DatabaseErrorPageOptions.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 cookie-based authentication to the request pipeline. app.UseIdentity(); // Add authentication middleware to the request pipeline. You can configure options such as Id and Secret in the ConfigureServices method. // For more information see http://go.microsoft.com/fwlink/?LinkID=532715 // app.UseFacebookAuthentication(); // app.UseGoogleAuthentication(); // app.UseMicrosoftAccountAuthentication(); // app.UseTwitterAuthentication(); // Add MVC to the request pipeline. app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller=Home}/{action=Index}/{id?}"); // Uncomment the following line to add a route for porting Web API 2 controllers. // routes.MapWebApiRoute("DefaultApi", "api/{controller}/{id?}"); }); } } public class TimeRecorderMiddleware { RequestDelegate _next; public TimeRecorderMiddleware(RequestDelegate next) { _next = next; } public async Task Invoke(HttpContext context) { var sw = new Stopwatch(); sw.Start(); await _next(context); var newDiv = @"<div id=""process"">页面处理时间:{0} 毫秒</div></body>"; var text = string.Format(newDiv, sw.ElapsedMilliseconds); await context.Response.WriteAsync(text); } }}
0 0
- asp.net总结(5)
- ASP.NET 基础(5)
- ASP.NET 笔记-5
- ASP.NET 5 简介
- ASP.NET 5简介
- asp.net 5
- ASP.NET MVC 5
- ASP.NET MVC 5
- ASP.NET MVC 5
- ASP.NET MVC 5
- ASP.NET MVC 5
- ASP.NET MVC 5
- ASP.NET MVC 5
- ASP.NET MVC 5
- ASP.NET MVC 5
- ASP.NET 5概观(ASP.NET 5 Overview)
- ASP.NET 5概观 (ASP.NET 5 Overview)
- [ASP.Net MVC 5 - 01] ASP.Net MVC and Azure
- 字典
- with as --工作备忘2016/1/13
- cocos2d-x 卓上改变工程图标的步骤
- CCT之CAMERA TUNNING调试学习总结
- android 省略号Bug
- asp.net 5
- 修改404页面,防止暴露环境信息
- Ubuntu环境下Neo4j图数据库的安装与测试
- 两张表合并统计
- 关于springMVC的下载图片
- Swift-概览
- gstreamer 捕获图像+存储示例代码
- OSG中的示例程序简介
- 水平进度条ProgressBar(progressBarStyleHorizontal)