本文整理汇总了C#中IAppBuilder.Use方法的典型用法代码示例。如果您正苦于以下问题:C# IAppBuilder.Use方法的具体用法?C# IAppBuilder.Use怎么用?C# IAppBuilder.Use使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IAppBuilder
的用法示例。
在下文中一共展示了IAppBuilder.Use方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Configuration
public void Configuration(IAppBuilder app)
{
var settings = new ApplicationSettings();
if (settings.MigrateDatabase)
{
// Perform the required migrations
DoMigrations();
}
var kernel = SetupNinject(settings);
app.Use(typeof(DetectSchemeHandler));
if (settings.RequireHttps)
{
app.Use(typeof(RequireHttpsHandler));
}
app.UseShowExceptions();
// This needs to run before everything
app.Use(typeof(AuthorizationHandler), kernel.Get<IAuthenticationTokenService>());
SetupSignalR(kernel, app);
SetupWebApi(kernel, app);
SetupMiddleware(settings, app);
SetupNancy(kernel, app);
SetupErrorHandling();
}
示例2: ConfigAuth
public void ConfigAuth(IAppBuilder app)
{
app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType);
app.UseCookieAuthentication(new CookieAuthenticationOptions {});
//[email protected]
//Azure680628
app.Use(async (context, next) =>
{
await next.Invoke();
});
app.UseOpenIdConnectAuthentication(
new OpenIdConnectAuthenticationOptions
{
// Client Id of Application
ClientId = "24e8d712-4765-48f1-9698-9e335da6f780",
// The authority provides a discoverable openid service
//https://login.windows.net/JohnsonAzureAD.onmicrosoft.com/.well-known/openid-configuration
// The keys
//https://login.windows.net/common/discovery/keys
Authority = "https://login.windows.net/JohnsonAzureAD.onmicrosoft.com",
PostLogoutRedirectUri = "http://localhost:53509/"
});
app.Use(async (context, next) =>
{
await next.Invoke();
});
}
示例3: Configuration
public void Configuration(IAppBuilder app)
{
if (Debugger.IsAttached)
{
app.Use(async (_http, _next) =>
{
await _next();
Console.WriteLine($"{_http.Response.StatusCode}: {_http.Request.Uri}");
});
}
app.Use((_http, _next) =>
{
if (_http.Request.Headers.ContainsKey("Origin"))
{
_http.Response.Headers.Set("Access-Control-Allow-Origin", "*");
}
return _next();
});
foreach (var _subStartup in _Kernel.GetAll<ISubStartup>())
{
app.Map(_subStartup.Path, _subApp => _subStartup.Configuration(_subApp));
}
}
示例4: Configuration
public void Configuration(IAppBuilder app)
{
var configuration = new JabbrConfiguration();
if (configuration.MigrateDatabase)
{
// Perform the required migrations
DoMigrations();
}
var kernel = SetupNinject(configuration);
app.Use(typeof(DetectSchemeHandler));
if (configuration.RequireHttps)
{
app.Use(typeof(RequireHttpsHandler));
}
app.UseErrorPage();
SetupAuth(app, kernel);
SetupSignalR(kernel, app);
SetupWebApi(kernel, app);
SetupMiddleware(kernel, app);
SetupNancy(kernel, app);
SetupErrorHandling();
}
示例5: MiddlewaresAtDifferentStagesConfiguration
public void MiddlewaresAtDifferentStagesConfiguration(IAppBuilder app)
{
app.Use((context, next) =>
{
//Create a custom object in the dictionary to push middlewareIds.
context.Set<Stack<int>>("stack", new Stack<int>());
return next.Invoke();
});
var stageTuples = new Tuple<RequestNotification, PipelineStage>[]
{
new Tuple<RequestNotification, PipelineStage>(RequestNotification.AuthenticateRequest, PipelineStage.Authenticate),
new Tuple<RequestNotification, PipelineStage>(RequestNotification.AuthenticateRequest, PipelineStage.PostAuthenticate),
new Tuple<RequestNotification, PipelineStage>(RequestNotification.AuthorizeRequest, PipelineStage.Authorize),
new Tuple<RequestNotification, PipelineStage>(RequestNotification.AuthorizeRequest, PipelineStage.PostAuthorize),
new Tuple<RequestNotification, PipelineStage>(RequestNotification.ResolveRequestCache, PipelineStage.ResolveCache),
new Tuple<RequestNotification, PipelineStage>(RequestNotification.ResolveRequestCache, PipelineStage.PostResolveCache),
new Tuple<RequestNotification, PipelineStage>(RequestNotification.MapRequestHandler, PipelineStage.MapHandler),
new Tuple<RequestNotification, PipelineStage>(RequestNotification.MapRequestHandler, PipelineStage.PostMapHandler),
new Tuple<RequestNotification, PipelineStage>(RequestNotification.AcquireRequestState, PipelineStage.AcquireState),
new Tuple<RequestNotification, PipelineStage>(RequestNotification.AcquireRequestState, PipelineStage.PostAcquireState),
new Tuple<RequestNotification, PipelineStage>(RequestNotification.PreExecuteRequestHandler, PipelineStage.PreHandlerExecute),
};
for (int middlewareId = 0; middlewareId < stageTuples.Length; middlewareId++)
{
var stage = stageTuples[middlewareId];
app.Use<IntegratedPipelineMiddleware>(stage.Item1, middlewareId);
app.UseStageMarker(stage.Item2);
}
}
示例6: Configuration
public void Configuration(IAppBuilder builder)
{
builder.UseAlpha("a", "b");
builder.UseFunc(app => Alpha.Invoke(app, "a", "b"));
builder.UseFunc(Alpha.Invoke, "a", "b");
builder.Use(Beta.Invoke("a", "b"));
builder.UseFunc(Beta.Invoke, "a", "b");
builder.UseGamma("a", "b");
builder.Use(typeof(Gamma), "a", "b");
builder.UseType<Gamma>("a", "b");
builder.UseFunc<AppFunc>(app => new Gamma(app, "a", "b").Invoke);
builder.Use(typeof(Delta), "a", "b");
builder.UseType<Delta>("a", "b");
builder.UseFunc<AppFunc>(app => new Delta(app, "a", "b").Invoke);
builder.Run(this);
}
示例7: Configuration
// Invoked once at startup to configure your application.
public void Configuration(IAppBuilder builder)
{
builder.Use((context, next) => { context.Response.Headers.Add("MyHeader", new [] { "abc" }); return next(); });
builder.UseStaticFiles("/Client");
//builder.UseFileServer(new FileServerOptions()
//{
// RequestPath = new PathString("/Client"),
// FileSystem = new PhysicalFileSystem(".\\Client")
//});
builder.Use<BasicAuthentication>();
HttpConfiguration config = new HttpConfiguration();
config.Routes.MapHttpRoute("Default", "api/Customer/{customerID}", new { controller="CustomerWebApi", customerID = RouteParameter.Optional });
var oDataBuilder = new ODataConventionModelBuilder();
oDataBuilder.EntitySet<Customer>("Customer");
config.Routes.MapODataRoute("odata", "odata", oDataBuilder.GetEdmModel());
// Use this if you want XML instead of JSON
//config.Formatters.XmlFormatter.UseXmlSerializer = true;
//config.Formatters.Remove(config.Formatters.JsonFormatter);
config.Formatters.JsonFormatter.UseDataContractJsonSerializer = true;
//config.Formatters.Remove(config.Formatters.XmlFormatter);
builder.UseWebApi(config);
}
示例8: Configuration
public void Configuration(IAppBuilder app)
{
// Show an error page
app.UseErrorPage();
// Logging component
app.Use<LoggingComponent>();
// Configure web api routing
var config = new HttpConfiguration();
config.MapHttpAttributeRoutes();
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
// Use web api middleware
app.UseWebApi(config);
// Throw an exception
app.Use(async (context, next) =>
{
if (context.Request.Path.ToString() == "/fail")
throw new Exception("Doh!");
await next();
});
// Welcome page
app.UseWelcomePage("/");
}
示例9: Configuration
public void Configuration(IAppBuilder app)
{
var httpConfiguration = new HttpConfiguration();
// Configure Web API Routes:
// - Enable Attribute Mapping
// - Enable Default routes at /api.
httpConfiguration.MapHttpAttributeRoutes();
httpConfiguration.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{action}/{id}",
defaults: new { id = RouteParameter.Optional },
constraints: null
);
app.Use<SimpleLogger>();
app.Use<AuthenticationCheck>();
app.UseWebApi(httpConfiguration);
// Make ./public the default root of the static files in our Web Application.
app.UseFileServer(new FileServerOptions
{
RequestPath = new PathString(string.Empty),
FileSystem = new PhysicalFileSystem("./public"),
EnableDirectoryBrowsing = true,
});
app.UseStageMarker(PipelineStage.MapHandler);
}
示例10: Configuration
public void Configuration(IAppBuilder app)
{
//Listando todo o pipeline
app.Use(async (environment, next) =>
{
foreach (var pair in environment.Environment)
{
Console.WriteLine("{0} : {1}", pair.Key, pair.Value);
}
await next();
});
//Exibindo o que foi requisitado e a resposta
app.Use(async (environment, next) =>
{
Console.WriteLine("Requisição: {0}", environment.Request.Path);
await next();
Console.WriteLine("Resposta: {0}", environment.Response.StatusCode);
});
app.Run(ctx =>
{
return ctx.Response.WriteAsync("Fim!");
});
}
示例11: CreateLoggerConfiguration
public void CreateLoggerConfiguration(IAppBuilder app)
{
app.SetLoggerFactory(new LoggerFactory());
app.Use<LoggingMiddleware1>(app);
app.Use<LoggingMiddleware2>(app);
}
示例12: Configuration
public void Configuration(IAppBuilder app)
{
// app.UseWelcomePage("/");
//app.Use(new Func<AppFunc, AppFunc>(
// next => (
// env =>
// {
// string strText = "原始方式的Owin";
// var response = env["owin.ResponseBody"] as Stream;
// var responseHeaders = env["owin.ResponseHeader"] as Dictionary<string, string[]>;
// responseHeaders.Add("content-type", "text-plain");
// return response.WriteAsync(Encoding.UTF8.GetBytes(strText), 0, strText.Length);
// }
// )));
app.Use<HelloWorldMiddleware>();
app.Use<NonebaseMiddleware>();
app.Use((context, next) => {
TextWriter output = context.Get<TextWriter>("host.TraceOutput");
return next().ContinueWith(result =>
{
output.WriteLine("Scheme {0} : Method {1} : Path {2} : MS {3}",
context.Request.Scheme, context.Request.Method, context.Request.Path, getTime());
});
});
// 有关如何配置应用程序的详细信息,请访问 http://go.microsoft.com/fwlink/?LinkID=316888
app.Run(context => {
context.Response.ContentType = "text/plain";
return context.Response.WriteAsync("Hello Owin from selfhost!");
});
}
示例13: Configuration
public void Configuration(IAppBuilder app)
{
#if DEBUG
app.UseErrorPage();
#endif
app.Use(
async (context, next) =>
{
// Log all exceptions and incoming requests
Console.WriteLine("{0} {1} {2}", context.Request.Method, context.Request.Path, context.Request.QueryString);
try
{
await next();
}
catch (Exception exception)
{
Console.WriteLine(exception.ToString());
throw;
}
});
var contentFileSystem = new PhysicalFileSystem("Content");
app.UseBabel(new BabelFileOptions() { StaticFileOptions = new StaticFileOptions() { FileSystem = contentFileSystem }});
app.UseFileServer(new FileServerOptions() { FileSystem = contentFileSystem });
app.Use<CommentsMiddleware>();
}
示例14: Configuration
public void Configuration(IAppBuilder app)
{
var settings = new ApplicationSettings();
if (settings.MigrateDatabase)
{
// Perform the required migrations
DoMigrations();
}
var kernel = SetupNinject(settings);
app.Use(typeof(DetectSchemeHandler));
if (settings.RequireHttps)
{
app.Use(typeof(RequireHttpsHandler));
}
app.UseShowExceptions();
SetupAuth(app, kernel);
SetupSignalR(kernel, app);
SetupWebApi(kernel, app);
SetupMiddleware(kernel, app, settings);
SetupNancy(kernel, app);
SetupErrorHandling();
}
示例15: Configuration
/// <summary>
/// The Startup configuration sets up a pipeline with three middleware components, the first two displaying diagnostic information
/// and the last one responding to events (and also displaying diagnostic information). The PrintCurrentIntegratedPipelineStage
/// method displays the integrated pipeline event this middleware is invoked on and a message.
/// </summary>
public void Configuration(IAppBuilder app)
{
app.Use((context, next) =>
{
PrintCurrentIntegratedPipelineStage(context, "Middleware 1");
return next.Invoke();
});
app.Use((context, next) =>
{
PrintCurrentIntegratedPipelineStage(context, "2nd MW");
return next.Invoke();
});
// You can mark OMCs to execute at specific stages of the pipeline by using the IAppBuilder UseStageMarker() extension method.
// To run a set of middleware components during a particular stage, insert a stage marker right after the last component is the set
// during registration. There are rules on which stage of the pipeline you can execute middleware and the order components must run
// (The rules are explained later in the tutorial). Add the UseStageMarker method to the Configuration code as shown below:
app.UseStageMarker(PipelineStage.Authenticate);
app.Run(context =>
{
PrintCurrentIntegratedPipelineStage(context, "3rd MW");
return context.Response.WriteAsync("Hello world");
});
app.UseStageMarker(PipelineStage.ResolveCache);
}