本文整理汇总了C#中IApplicationBuilder.UseCors方法的典型用法代码示例。如果您正苦于以下问题:C# IApplicationBuilder.UseCors方法的具体用法?C# IApplicationBuilder.UseCors怎么用?C# IApplicationBuilder.UseCors使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IApplicationBuilder
的用法示例。
在下文中一共展示了IApplicationBuilder.UseCors方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Configure
public void Configure(IApplicationBuilder app)
{
JwtSecurityTokenHandler.DefaultInboundClaimTypeMap = new Dictionary<string, string>();
// IdentityServer3 hardcodes the audience as '{host-address}/resources'.
// It is suggested to do the validation on scopes.
// That's why audience validation is disabled with 'ValidateAudience = false' below.
app.UseJwtBearerAuthentication(options =>
{
options.Authority = "http://localhost:44300/";
options.TokenValidationParameters.ValidateAudience = false;
options.AutomaticAuthentication = true;
if (_hostingEnv.IsDevelopment())
{
options.ConfigurationManager = new ConfigurationManager<OpenIdConnectConfiguration>(
metadataAddress: $"{options.Authority}.well-known/openid-configuration",
configRetriever: new OpenIdConnectConfigurationRetriever(),
docRetriever: new HttpDocumentRetriever { RequireHttps = false }
);
}
});
app.UseCors(policy => policy.AllowAnyHeader().AllowAnyMethod().AllowAnyOrigin())
.UseMiddleware<AuthenticatedUserLoggingMiddleware>()
.UseMvc();
}
示例2: Configure
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
loggerFactory.AddConsole(LogLevel.Verbose);
loggerFactory.AddDebug(LogLevel.Verbose);
ILogger log = loggerFactory.CreateLogger("testlog");
log.LogInformation("AppSettings:AllowedOrigins: " + string.Join(" , ", Configuration.Get<string[]>("AppSettings:AllowedOrigins")));
app.UseStaticFiles();
app.UseCors(builder =>
{
builder.WithOrigins(Configuration.Get<string[]>("AppSettings:AllowedOrigins")) // TODO: revisit and check if this can be more strict and still allow preflight OPTION requests
.AllowAnyMethod()
.AllowAnyHeader();
});
app.UseIISPlatformHandler();
JwtSecurityTokenHandler.DefaultInboundClaimTypeMap.Clear();
app.UseIdentityServerAuthentication(options =>
{
options.Authority = "http://localhost:5020";
options.ScopeName = "openid";
options.AutomaticAuthenticate = true;
options.AutomaticChallenge = true;
});
app.UseMvc();
}
示例3: Configure
// Configure is called after ConfigureServices is called.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
var builder = new ContainerBuilder();
JwtSecurityTokenHandler.DefaultInboundClaimTypeMap = new Dictionary<string, string>();
//app.UseCookieAuthentication(options =>
//{
// options.AuthenticationScheme = "Temp";
// options.AutomaticAuthentication = false;
//}, "external");
// Configure the HTTP request pipeline.
//app.UseStaticFiles();
// Add the following route for porting Web API 2 controllers.
// routes.MapWebApiRoute("DefaultApi", "api/{controller}/{id?}");
app.UseOAuthBearerAuthentication(options =>
{
options.Authority = "https://localhost:44333/core";
//options.Authority = "https://karamaidentityserver.azurewebsites.net/core";
options.Audience = "https://karama.com/resources";
options.AutomaticAuthentication = true;
});
app.UseMiddleware<RequiredScopesMiddleware>(new List<string> { "api3" });
app.UseCors("AllowSpecificOrigins");
// Add MVC to the request pipeline.
app.UseMvc();
}
示例4: Configure
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
loggerFactory.AddConsole(Configuration.GetSection("ConsoleLogging"));
loggerFactory.AddDebug(LogLevel.Debug);
// CORS
app.UseCors((policy) => {
policy.AllowAnyHeader();
policy.AllowAnyMethod();
policy.AllowAnyOrigin();
policy.AllowCredentials();
});
app.UseApiExtensions();
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "api/{controller}/{id?}");
});
app.UseSwagger();
app.UseSwaggerUi();
app.UseSwaggerUiRedirect();
}
示例5: Configure
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
loggerFactory.AddConsole();
loggerFactory.AddDebug();
app.UseIISPlatformHandler();
app.UseCors(policy =>
{
policy.WithOrigins(
"http://localhost:28895",
"http://localhost:7017");
policy.AllowAnyHeader();
policy.AllowAnyMethod();
});
JwtSecurityTokenHandler.DefaultInboundClaimTypeMap.Clear();
app.UseIdentityServerAuthentication(options =>
{
options.Authority = Clients.Constants.BaseAddress;
options.ScopeName = "api1";
options.ScopeSecret = "secret";
options.AutomaticAuthenticate = true;
options.AutomaticChallenge = true;
});
app.UseMvc();
}
示例6: Configure
public void Configure(IApplicationBuilder app, IHostingEnvironment environment)
{
Console.WriteLine("Startup:Configure");
try
{
app.UseDeveloperExceptionPage();
app.UseCors("AllowAll");
//app.UseWelcomePage();
// Add the platform handler to the request pipeline.
app.UseIISPlatformHandler();
// Configure the HTTP request pipeline.
app.UseStaticFiles();
app.UseSession();
app.UseMvc();
//app.Run(async (context) =>
//{
// await context.Response.WriteAsync("Hello World!");
//});
//Already earliest time to init as DbContext Services required to setup at ConfigureServices() first
OriginChecker.Init(app.ApplicationServices);
FileManager.Init(Configuration["FileManager:FullWebRoot"],
Path.Combine(environment.WebRootPath, Configuration["FileManager:RepositoryRootFolderName"])
//(PhotoManagementDb) app.ApplicationServices.GetService(typeof (PhotoManagementDb))
);
}
catch (Exception e)
{
Console.WriteLine($"Error:{e.Message}\nAt:{e.Source}\nStack:{e.StackTrace}");
Console.ReadLine();
}
}
示例7: Configure
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
loggerFactory.AddDebug();
var section = Configuration.GetSection("MongoDB");
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseExceptionHandler("/Home/Error");
}
app.UseIISPlatformHandler();
app.UseCors("AllowAll");
app.UseStaticFiles();
app.UseMvc(routes =>
{
routes.MapRoute(
name:"api",
template: "api/{controller}/{id?}"
);
});
}
示例8: Configure
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IApplicationEnvironment env)
{
app.UseIISPlatformHandler();
app.UseDeveloperExceptionPage();
app.UseCors("corsGlobalPolicy");
var certFile = env.ApplicationBasePath + "\\cert.pfx";
var idsrvOptions = new IdentityServerOptions
{
Factory = new IdentityServerServiceFactory()
.UseInMemoryUsers(Users.Get())
.UseInMemoryClients(Clients.Get())
.UseInMemoryScopes(Scopes.Get()),
SigningCertificate = new X509Certificate2(certFile, "christus"),
AuthenticationOptions = new AuthenticationOptions
{
EnablePostSignOutAutoRedirect = true
},
LoggingOptions = new LoggingOptions
{
EnableHttpLogging = true,
EnableWebApiDiagnostics = true,
WebApiDiagnosticsIsVerbose = true
},
};
app.UseIdentityServer(idsrvOptions);
}
示例9: Configure
public void Configure(IApplicationBuilder app)
{
app.UseCultureReplacer();
app.UseCors(policy => policy.WithOrigins("http://example.com"));
app.UseMvc();
}
示例10: Configure
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
loggerFactory.MinimumLevel = LogLevel.Information;
loggerFactory.AddConsole();
loggerFactory.AddDebug();
app.UseIISPlatformHandler();
app.UseExceptionHandler("/Home/Error");
app.UseCors("corsGlobalPolicy");
app.UseStaticFiles();
JwtSecurityTokenHandler.DefaultInboundClaimTypeMap = new Dictionary<string, string>();
app.UseJwtBearerAuthentication(options =>
{
options.Authority = "https://localhost:44345";
options.Audience = "https://localhost:44345/resources";
options.AutomaticAuthenticate = true;
});
app.UseMiddleware<RequiredScopesMiddleware>(new List<string> { "dataEventRecords" });
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
}
示例11: Configure
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, IConfigurationRoot configuration)
{
loggerFactory.AddConsole(configuration.GetSection("Logging"));
loggerFactory.AddDebug();
// For more details on creating database during deployment see http://go.microsoft.com/fwlink/?LinkID=615859
try
{
using (var serviceScope = app.ApplicationServices.GetRequiredService<IServiceScopeFactory>()
.CreateScope())
{
using (var db = serviceScope.ServiceProvider.GetService<ApplicationDbContext>())
{
db.Database.EnsureCreated();
db.Database.Migrate();
}
}
}
catch (Exception exception)
{
}
app.UseCors("AllowAllOrigins"); // TODO: allow collection of allowed origins per client
app.UseIISPlatformHandler();
app.UseStaticFiles();
app.UseMvc();
}
示例12: Configure
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
loggerFactory.AddConsole();
loggerFactory.AddDebug();
app.UseExceptionHandler("/Home/Error");
app.UseCors("corsGlobalPolicy");
app.UseStaticFiles();
JwtSecurityTokenHandler.DefaultInboundClaimTypeMap.Clear();
IdentityServerAuthenticationOptions identityServerValidationOptions = new IdentityServerAuthenticationOptions
{
Authority = "https://localhost:44318/",
AllowedScopes = new List<string> { "dataEventRecords" },
ApiSecret = "dataEventRecordsSecret",
ApiName = "dataEventRecords",
AutomaticAuthenticate = true,
SupportedTokens = SupportedTokens.Both,
// TokenRetriever = _tokenRetriever,
// required if you want to return a 403 and not a 401 for forbidden responses
AutomaticChallenge = true,
};
app.UseIdentityServerAuthentication(identityServerValidationOptions);
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
}
示例13: Configure
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
loggerFactory.AddDebug();
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseCors("CorsPolicy");
app.UseDefaultFiles();
app.UseStaticFiles();
var tokenValidationParameters = CreateTokenValidationParameters();
app.UseJwtBearerAuthentication(new JwtBearerOptions
{
AutomaticAuthenticate = true,
AutomaticChallenge = true,
TokenValidationParameters = tokenValidationParameters
});
app.UseMvc(routes =>
{
routes.MapRoute(
name: "Default",
template: "api/{controller}/{action}/{id?}"
);
});
}
示例14: Configure
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
//loggerFactory.AddConsole(Configuration.GetSection("Logging"));
if (env.IsDevelopment())
{
loggerFactory.AddDebug();
app.UseBrowserLink();
app.UseDeveloperExceptionPage();
}
else
{
app.UseExceptionHandler("/Home/Error");
}
app.UseIISPlatformHandler(options => options.AuthenticationDescriptions.Clear());
app.UseStaticFiles();
app.UseCors(builder =>
{
builder.AllowAnyOrigin();
builder.AllowAnyHeader();
builder.WithMethods("GET", "POST");
});
app.Use(async (context, next) =>
{
context.Response.Headers.Remove("Server");
await next();
});
app.UseMvc(routes =>
{
routes.MapRoute("default", "{controller=Home}/{action=Index}/{id?}");
});
}
示例15: Configure
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
loggerFactory.AddDebug();
app.UseStaticFiles();
app.UseStaticFiles(new StaticFileOptions()
{
FileProvider = new PhysicalFileProvider(
Path.Combine(Directory.GetCurrentDirectory(), @"Images")),
RequestPath = new PathString("/Images")
});
// Add MVC to the request pipeline.
app.UseMvc(routes =>
{
routes.MapRoute(name: "areaRoute",
template: "{area}/{controller}/{action}",
defaults: new { area = "v2", controller = "Images", action = "Index" });
routes.MapRoute(
name: "default",
template: "{controller}/{action}/{id?}",
defaults: new { controller = "Home", action = "Index" });
});
// Add the following route for porting Web API 2 controllers.
// routes.MapWebApiRoute("DefaultApi", "api/{controller}/{id?}");
app.UseCors("default");
app.UseMvc();
}