Skip to content

Instantly share code, notes, and snippets.

View StephanyBatista's full-sized avatar

Stephany Henrique Batista StephanyBatista

View GitHub Profile
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
loggerFactory.AddDebug();
app.UseApplicationInsightsRequestTelemetry();
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
public void ConfigureServices(IServiceCollection services)
{
// Add framework services.
services.AddApplicationInsightsTelemetry(Configuration);
services.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
services.AddIdentity<ApplicationUser, IdentityRole>()
.AddEntityFrameworkStores<ApplicationDbContext>()
public Startup(IHostingEnvironment env)
{
var builder = new ConfigurationBuilder()
.SetBasePath(env.ContentRootPath)
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
.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
{
"ApplicationInsights": {
"InstrumentationKey": ""
},
"Data": {
"DefaultConnection": {
"ConnectionString": "Server=(localdb)\\mssqllocaldb;Database=aspnet5-MiddlewareArticle-e63ce29d-6763-40c9-9ac5-773c142ceb0d;Trusted_Connection=True;MultipleActiveResultSets=true"
}
},
"Logging": {
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
app.UseMiddleware<ResponseTime>(); //Our Middleware
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
loggerFactory.AddDebug();
//...
//Continue with others codes
using Microsoft.AspNet.Builder;
using Microsoft.AspNet.Http;
using System.Diagnostics;
using System.IO;
using System.Threading.Tasks;
namespace MiddlewareArticle.Middleware
{
public class ResponseTime
{
@StephanyBatista
StephanyBatista / Startup.cs
Created April 29, 2016 20:01
Example of middleware in Startup class
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
loggerFactory.AddDebug();
app.UseApplicationInsightsRequestTelemetry();
if (env.IsDevelopment())
{
app.UseBrowserLink(); //Middleware
@StephanyBatista
StephanyBatista / basicServerWeb.js
Created January 11, 2016 16:28
How create a server web with routes
var http = require('http');
var newRequest = function(request, response) {
response.writeHead(200, {"Content-Type": "text/html"});
if(request.url == '/')
response.write("<h1>Home</h1>");
else if(request.url == '/sobre')
response.write("<h1>About</h1>");
else if(request.url == '/contato')
@StephanyBatista
StephanyBatista / basicServerWeb.js
Created January 11, 2016 16:24
How create a server web
var http = require('http');
var newRequest = function(request, response) {
response.writeHead(200, {"Content-Type": "text/html"});
response.write("<h1>Hello World!</h1>");
response.end();
}
var server = http.createServer(newRequest);
var express = require('express');
var app = express();
app.get('/', function (req, res) {
res.send('Hello World!');
});
var server = app.listen(3000, function () {
var host = server.address().address;
var port = server.address().port;