本文整理汇总了C#中IAppBuilder.UseHandlerAsync方法的典型用法代码示例。如果您正苦于以下问题:C# IAppBuilder.UseHandlerAsync方法的具体用法?C# IAppBuilder.UseHandlerAsync怎么用?C# IAppBuilder.UseHandlerAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IAppBuilder
的用法示例。
在下文中一共展示了IAppBuilder.UseHandlerAsync方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Configuration
public void Configuration(IAppBuilder app)
{
app.UseHandlerAsync((req, res) =>
{
res.ContentType = "text/plain";
return res.WriteAsync("Hello World!");
});
}
示例2: Configuration
public void Configuration(IAppBuilder app)
{
app.UseFileServer(true);
app.UseWelcomePage("/welkom");
app.UseHandlerAsync((req, res, next) =>
{
if (req.Path == "/owin")
{
res.StatusCode = 302;
res.AddHeader("Location", "http://owin.org/");
return Task.FromResult(0);
}
return next();
});
app.UseHandlerAsync(RequestDump);
}
示例3: Configuration
public void Configuration(IAppBuilder app)
{
ConfigureApi(app);
app.UseNancy(new NancyOptions { Bootstrapper = new NancyBootstrapper() });
app.UseHandlerAsync((req, res) =>
{
res.ContentType = "text/plain";
return res.WriteAsync("OWIN Web Application Final step");
});
}
示例4: Configuration
public void Configuration(IAppBuilder app)
{
app.Use<LoggerMiddleware>();
var config = new HttpConfiguration();
config.Routes.MapHttpRoute("default", "{controller}");
app.UseWebApi(config);
app.UseHandlerAsync((req, res) =>
{
res.ContentType = "text/plain";
return res.WriteAsync("Hello World!");
});
}
示例5: Configuration
public void Configuration(IAppBuilder app)
{
//app.UseOpenIdConnectAuthentication(
// new OpenIdConnectAuthenticationOptions
// {
// ClientId = "oidccode",
// ClientSecret = "secret",
// Scope = "openid profile",
// ReturnPath = "/oidccallback",
// RedirectUri = new Uri("https://localhost:44310/oidccallback"),
// AuthorizeEndpoint = new Uri("https://idsrv.local/issue/oidc/authorize"),
// SigninAsAuthenticationType = "Federation"
// });
// authentication
//app.Use(typeof(AuthenticationMiddleware));
//app.Use(typeof(SetPrincipalMiddleware));
// web api
//var httpConfig = new HttpConfiguration();
//httpConfig.Routes.MapHttpRoute(
// "default",
// "api/{controller}");
//app.UseWebApi(httpConfig);
// plain http handler
app.UseHandlerAsync((req, res) =>
{
res.ContentType = "text/plain";
if (Thread.CurrentPrincipal.Identity.IsAuthenticated)
{
return res.WriteAsync("Hello " + Thread.CurrentPrincipal.Identity.Name);
}
else
{
//res.StatusCode = 401;
return res.WriteAsync("Hello stranger!");
}
});
}
示例6: Configuration
public void Configuration(IAppBuilder app)
{
var webserverOptions = new WebserverOptions
{
BasePath = Environment.CurrentDirectory
};
app.Use(typeof(TraceMiddleware));
app.UseHandlerAsync((request, response, next) =>
{
response.AddHeader("Server", "dotnetpro Webserver");
return next();
});
app.Use(typeof(GitReceivePackMiddleware), webserverOptions);
app.Use(typeof(IsPrivateFolderMiddleware), webserverOptions);
app.Use(typeof(ResourceExistMiddleware), webserverOptions);
app.Use(typeof(DefaultMiddleware), webserverOptions);
}
示例7: Configuration
public void Configuration(IAppBuilder app)
{
var logger = app.CreateLogger("Katana.Sandbox.WebServer");
logger.WriteInformation("Application Started");
app.UseHandlerAsync(async (req, res, next) =>
{
req.TraceOutput.WriteLine("{0} {1}{2}", req.Method, req.PathBase, req.Path);
await next();
req.TraceOutput.WriteLine("{0} {1}{2}", res.StatusCode, req.PathBase, req.Path);
});
app.UseFormsAuthentication(new FormsAuthenticationOptions
{
AuthenticationType = "Application",
AuthenticationMode = AuthenticationMode.Passive,
LoginPath = "/Login",
LogoutPath = "/Logout",
});
app.UseExternalSignInCookie();
app.UseFacebookAuthentication(new FacebookAuthenticationOptions
{
SignInAsAuthenticationType = "External",
AppId = "615948391767418",
AppSecret = "c9b1fa6b68db835890ce469e0d98157f",
// Scope = "email user_birthday user_website"
});
app.UseGoogleAuthentication();
app.UseTwitterAuthentication("6XaCTaLbMqfj6ww3zvZ5g", "Il2eFzGIrYhz6BWjYhVXBPQSfZuS4xoHpSSyD9PI");
app.UseMicrosoftAccountAuthentication("000000004C0EA787", "QZde5m5HHZPxdieV0lOy7bBVTbVqR9Ju");
app.UseOAuthBearerAuthentication(new OAuthBearerAuthenticationOptions
{
});
// CORS support
app.UseHandlerAsync(async (req, res, next) =>
{
// for auth2 token requests, and web api requests
if (req.Path == "/Token" || req.Path.StartsWith("/api/"))
{
// if there is an origin header
var origin = req.GetHeader("Origin");
if (!string.IsNullOrEmpty(origin))
{
// allow the cross-site request
res.AddHeader("Access-Control-Allow-Origin", origin);
}
// if this is pre-flight request
if (req.Method == "OPTIONS")
{
// respond immediately with allowed request methods and headers
res.StatusCode = 200;
res.AddHeaderJoined("Access-Control-Allow-Methods", "GET", "POST");
res.AddHeaderJoined("Access-Control-Allow-Headers", "authorization");
// no further processing
return;
}
}
// continue executing pipeline
await next();
});
app.UseOAuthAuthorizationServer(new OAuthAuthorizationServerOptions
{
AuthorizeEndpointPath = "/Authorize",
TokenEndpointPath = "/Token",
Provider = new OAuthAuthorizationServerProvider
{
OnValidateClientCredentials = OnValidateClientCredentials,
OnValidateResourceOwnerCredentials = OnValidateResourceOwnerCredentials,
},
});
var config = new HttpConfiguration();
config.Routes.MapHttpRoute("Default", "api/{controller}");
app.UseWebApi(config);
}
示例8: Configuration
public void Configuration(IAppBuilder builder)
{
builder.UseHandlerAsync((request, response) => response.WriteAsync("Sup"));
}
示例9: Configuration
// Invoked once at startup to configure your application.
public void Configuration(IAppBuilder builder)
{
builder.UseHandlerAsync(Invoke);
}