本文整理汇总了C#中IAppBuilder类的典型用法代码示例。如果您正苦于以下问题:C# IAppBuilder类的具体用法?C# IAppBuilder怎么用?C# IAppBuilder使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
IAppBuilder类属于命名空间,在下文中一共展示了IAppBuilder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Configuration
public void Configuration(IAppBuilder appBuilder)
{
// Configure Web API for self-host.
HttpConfiguration config = new HttpConfiguration();
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
appBuilder.UseWebApi(config);
var appFolder = Path.Combine(Directory.GetParent(AppDomain.CurrentDomain.BaseDirectory).Parent.Parent.FullName, "Webportal");
appBuilder.UseFileServer(new Microsoft.Owin.StaticFiles.FileServerOptions
{
RequestPath = new PathString(WebPortalUrl),
FileSystem = new PhysicalFileSystem(appFolder),
EnableDirectoryBrowsing = true
});
appBuilder.Map(PathString.Empty, a => a.Use<PortalRedirectionMiddelware>(WebPortalUrl));
appBuilder.Use<AdminMiddleware>();
}
示例2: Configuration
public void Configuration(IAppBuilder appBuilder)
{
var config = new HttpConfiguration();
config.MapHttpAttributeRoutes();
config.Routes.MapHttpRoute("DefaultApi", "api/{controller}/{id}", new {id = RouteParameter.Optional});
appBuilder.UseWebApi(config).UseNancy();
}
示例3: Configuration
// This code configures Web API. The Startup class is specified as a type
// parameter in the WebApp.Start method.
public void Configuration(IAppBuilder appBuilder)
{
// Configure Web API for self-host.
HttpConfiguration config = new HttpConfiguration();
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{action}/{id}",
defaults: new { id = RouteParameter.Optional }
);
// 默认返回Json数据
//config.Formatters.JsonFormatter.SupportedMediaTypes.Add(new MediaTypeHeaderValue("text/html"));
//var bson = new BsonMediaTypeFormatter();
//bson.SupportedMediaTypes.Add(new MediaTypeHeaderValue("application/bson"));
//config.Formatters.Add(bson);
config.Formatters.Add(new Raven.AspNet.WebApiExtensions.Formatters.MsgPackFormatter());
appBuilder.UseRequestScopeContext();
appBuilder.UseWebApi(config);
//CallContext
//appBuilder.Use(
}
示例4: 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}/{id}",
defaults: new { id = RouteParameter.Optional }
);
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);
}
示例5: 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);
}
示例6: Configuration
public void Configuration(IAppBuilder app)
{
//app.MapSignalR();
app.Map("/signalr", map =>
{
map.UseCors(CorsOptions.AllowAll);
var hubConfiguration = new HubConfiguration { EnableJSONP = true };
map.RunSignalR(hubConfiguration);
});
// Branch the pipeline here for requests that start with "/signalr"
//app.Map("/signalr", map =>
//{
// // Setup the CORS middleware to run before SignalR.
// // By default this will allow all origins. You can
// // configure the set of origins and/or http verbs by
// // providing a cors options with a different policy.
// map.UseCors(CorsOptions.AllowAll);
// var hubConfiguration = new HubConfiguration
// {
// // You can enable JSONP by uncommenting line below.
// // JSONP requests are insecure but some older browsers (and some
// // versions of IE) require JSONP to work cross domain
// // EnableJSONP = true
// };
// // Run the SignalR pipeline. We're not using MapSignalR
// // since this branch already runs under the "/signalr"
// // path.
// map.RunSignalR(hubConfiguration);
//});
}
示例7: ConfigureModules
private void ConfigureModules(IAppBuilder appBuilder)
{
appBuilder
.Use<ListenerModule>(registeredHandlers, Logger)
.MapSignalR(new HubConfiguration { EnableJavaScriptProxies = false, EnableJSONP = HubEnableJsonp })
.Use<Error404Module>();
}
示例8: Configuration
public void Configuration(IAppBuilder app)
{
app.MapSignalR<SendingConnection>("/sending-connection");
app.MapSignalR<TestConnection>("/test-connection");
app.MapSignalR<RawConnection>("/raw-connection");
app.MapSignalR<StreamingConnection>("/streaming-connection");
app.Use(typeof(ClaimsMiddleware));
ConfigureSignalR(GlobalHost.DependencyResolver, GlobalHost.HubPipeline);
var config = new HubConfiguration()
{
EnableDetailedErrors = true
};
app.MapSignalR(config);
app.Map("/cors", map =>
{
map.UseCors(CorsOptions.AllowAll);
map.MapSignalR<RawConnection>("/raw-connection");
map.MapSignalR();
});
app.Map("/basicauth", map =>
{
map.UseBasicAuthentication(new BasicAuthenticationProvider());
map.MapSignalR<AuthenticatedEchoConnection>("/echo");
map.MapSignalR();
});
BackgroundThread.Start();
}
示例9: Install
public static new void Install(HttpConfiguration config, IAppBuilder app)
{
config.SuppressHostPrincipal();
app.UseCors(CorsOptions.AllowAll);
app.MapSignalR();
var jSettings = new JsonSerializerSettings();
jSettings.Formatting = Formatting.Indented;
jSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
config.Formatters.Remove(config.Formatters.XmlFormatter);
config.Formatters.JsonFormatter.SerializerSettings = jSettings;
config.MapHttpAttributeRoutes();
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
}
示例10: ConfigureMobileApp
public static void ConfigureMobileApp(IAppBuilder app)
{
HttpConfiguration config = new HttpConfiguration();
#if DEBUG
config.Formatters.JsonFormatter.SerializerSettings.Formatting = Formatting.Indented;
config.IncludeErrorDetailPolicy = IncludeErrorDetailPolicy.Always;
#endif
new MobileAppConfiguration().UseDefaultConfiguration().ApplyTo(config);
config.Services.Add(typeof(IExceptionLogger), new AiExceptionLogger());
// Use Entity Framework Code First to create database tables based on your DbContext
Database.SetInitializer(new MobileServiceInitializer());
MobileAppSettingsDictionary settings = config.GetMobileAppSettingsProvider().GetMobileAppSettings();
if (string.IsNullOrEmpty(settings.HostName))
{
app.UseAppServiceAuthentication(new AppServiceAuthenticationOptions
{
// This middleware is intended to be used locally for debugging. By default, HostName will
// only have a value when running in an App Service application.
SigningKey = ConfigurationManager.AppSettings["SigningKey"],
ValidAudiences = new[] { ConfigurationManager.AppSettings["ValidAudience"] },
ValidIssuers = new[] { ConfigurationManager.AppSettings["ValidIssuer"] },
TokenHandler = config.GetAppServiceTokenHandler()
});
}
app.UseWebApi(config);
}
示例11: ConfigureAuth
// Para obtener más información sobre la configuración de la autenticación, visite http://go.microsoft.com/fwlink/?LinkId=301883
public void ConfigureAuth(IAppBuilder app)
{
// Habilitar la aplicación para que use una cookie para almacenar la información del usuario que inició sesión
// y almacenar también información acerca de un usuario que inicie sesión con un proveedor de inicio de sesión de un tercero.
// Es obligatorio si la aplicación permite a los usuarios iniciar sesión
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
LoginPath = new PathString("/Account/Login")
});
app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);
// Quitar las marcas de comentario de las líneas siguientes para habilitar el inicio de sesión con proveedores de inicio de sesión de terceros
//app.UseMicrosoftAccountAuthentication(
// clientId: "",
// clientSecret: "");
//app.UseTwitterAuthentication(
// consumerKey: "",
// consumerSecret: "");
//app.UseFacebookAuthentication(
// appId: "",
// appSecret: "");
//app.UseGoogleAuthentication();
}
示例12: Configuration
public void Configuration(IAppBuilder app)
{
app.UseOAuthBearerAuthentication(AccountController.OAuthBearerOptions);
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
LoginPath = new PathString("/Account/Login")
});
app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);
if (IsTrue("ExternalAuth.Facebook.IsEnabled"))
{
app.UseFacebookAuthentication(CreateFacebookAuthOptions());
}
if (IsTrue("ExternalAuth.Twitter.IsEnabled"))
{
app.UseTwitterAuthentication(CreateTwitterAuthOptions());
}
if (IsTrue("ExternalAuth.Google.IsEnabled"))
{
app.UseGoogleAuthentication(CreateGoogleAuthOptions());
}
}
示例13: Configuration
public void Configuration(IAppBuilder app)
{
var webApiConfiguration = ConfigureWebApi();
webApiConfiguration.EnsureInitialized();
app.UseWebApi(webApiConfiguration);
ConfigureHandlers();
}
示例14: ConfigureAuth
// For more information on configuring authentication, please visit http://go.microsoft.com/fwlink/?LinkId=301864
public void ConfigureAuth(IAppBuilder app)
{
// Configure the db context, user manager and signin manager to use a single instance per request
app.CreatePerOwinContext(ApplicationDbContext.Create);
app.CreatePerOwinContext<ApplicationUserManager>(ApplicationUserManager.Create);
app.CreatePerOwinContext<ApplicationSignInManager>(ApplicationSignInManager.Create);
// Enable the application to use a cookie to store information for the signed in user
// and to use a cookie to temporarily store information about a user logging in with a third party login provider
// Configure the sign in cookie
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
LoginPath = new PathString("/Account/Login"),
Provider = new CookieAuthenticationProvider
{
// Enables the application to validate the security stamp when the user logs in.
// This is a security feature which is used when you change a password or add an external login to your account.
OnValidateIdentity = SecurityStampValidator.OnValidateIdentity<ApplicationUserManager, ApplicationUser>(
validateInterval: TimeSpan.FromMinutes(30),
regenerateIdentity: (manager, user) => user.GenerateUserIdentityAsync(manager))
}
});
app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);
// Enables the application to temporarily store user information when they are verifying the second factor in the two-factor authentication process.
app.UseTwoFactorSignInCookie(DefaultAuthenticationTypes.TwoFactorCookie, TimeSpan.FromMinutes(5));
// Enables the application to remember the second login verification factor such as phone or email.
// Once you check this option, your second step of verification during the login process will be remembered on the device where you logged in from.
// This is similar to the RememberMe option when you log in.
app.UseTwoFactorRememberBrowserCookie(DefaultAuthenticationTypes.TwoFactorRememberBrowserCookie);
// Uncomment the following lines to enable logging in with third party login providers
//app.UseMicrosoftAccountAuthentication(
// clientId: "",
// clientSecret: "");
//app.UseTwitterAuthentication(
// consumerKey: "",
// consumerSecret: "");
//app.UseFacebookAuthentication(
// appId: "",
// appSecret: "");
//app.UseGoogleAuthentication(new GoogleOAuth2AuthenticationOptions()
//{
// ClientId = "",
// ClientSecret = ""
//});
//SignalR
GlobalHost.DependencyResolver.Register(typeof(IHubActivator), () => new UnityHubActivator(UnityConfig.GetConfiguredContainer()));
//var config = new HubConfiguration {EnableJSONP = true};
//app.MapSignalR(config);
app.MapSignalR();
}
示例15: ConfigureOAuth
public void ConfigureOAuth(IAppBuilder app)
{
app.UseOAuthBearerAuthentication(new OAuthBearerAuthenticationOptions());
app.UseOAuthAuthorizationServer(new OAuthAuthorizationServerOptions()
{
AllowInsecureHttp = true,
TokenEndpointPath = new PathString("/token"),
AccessTokenExpireTimeSpan = TimeSpan.FromMinutes(30),
Provider = new OAuthAuthorizationServerProvider
{
OnValidateClientAuthentication = async c=>c.Validated(),
OnGrantResourceOwnerCredentials = async c =>
{
using (var repo = new AuthRepository())
{
var user = await repo.FindUser(c.UserName, c.Password);
if (user == null)
{
c.Rejected();
throw new ApiException("User not existed or wrong password.");
}
}
var identity = new ClaimsIdentity(c.Options.AuthenticationType);
identity.AddClaims(new[] {new Claim(ClaimTypes.Name, c.UserName), new Claim(ClaimTypes.Role, "user")});
if (string.Equals(c.UserName, AppConfig.Manager, StringComparison.InvariantCultureIgnoreCase))
identity.AddClaims(new[] {new Claim(ClaimTypes.Name, c.UserName), new Claim(ClaimTypes.Role, "manager")});
c.Validated(identity);
}
},
});
}