asp.net 5
2016-01-13 10:21
495 查看
相关学习地址: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); } } }
相关文章推荐
- asp.net MVC在IIS7或7.5上的发布问题
- ASP.NET MVC 部分视图
- [Asp.net 5] Caching-缓存预告
- IIS 内部运行机制及Asp.Net执行过程详解
- 实现Asp.Net MVC无刷新分页
- ASP.Net学习笔记006--Get和Post的区别
- ASP.NET数据绑定之Repeater控件
- ASP.NET中DropDownList和ListBox实现两级联动功能
- LowercaseRoutesMVC ASP.NET MVC routes to lowercase URLs
- RaspberryPi自动连接多个无线,并且自动汇报IP
- casperJs的安装
- 如何用casperjs自动登入
- 好书推荐之ASP.NET MVC4框架揭秘
- ASP.NET 操作Cookie详解 增加,修改,删除
- ASP.NET伪静态的方法及相关资料
- asp.net 路径解惑
- 【ASP.NET】利用.ashx、Ajax、Session优化Repeater的使用
- win 8.1 下用 VS2013 和 IIS 发布 ASP.NET 网站
- asp 页面数据导出为word或者excel
- Asp.Net类型转换类(通用类)代码分享