当前位置: 首页>>代码示例>>C#>>正文


C# IServiceCollection.ConfigureCors方法代码示例

本文整理汇总了C#中IServiceCollection.ConfigureCors方法的典型用法代码示例。如果您正苦于以下问题:C# IServiceCollection.ConfigureCors方法的具体用法?C# IServiceCollection.ConfigureCors怎么用?C# IServiceCollection.ConfigureCors使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IServiceCollection的用法示例。


在下文中一共展示了IServiceCollection.ConfigureCors方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ConfigureServices

        //// This method gets called by a runtime.
        //// Use this method to add services to the container
        //public void ConfigureServices(IServiceCollection services)
        //{
        //    services.AddMvc();
        //    // Uncomment the following line to add Web API services which makes it easier to port Web API 2 controllers.
        //    // You will also need to add the Microsoft.AspNet.Mvc.WebApiCompatShim package to the 'dependencies' section of project.json.
        //    // services.AddWebApiConventions();
        //}
        // You probably need to change this return type - defaults to void
        public IServiceProvider ConfigureServices(IServiceCollection services)
        {
            //IServiceProvider
            // Add your various services such as MVC as normal
            services.AddMvc();

            services.AddCors();
            services.ConfigureCors(options =>
            {
                options.AddPolicy("AllowAll",
                    builder => builder.AllowAnyOrigin().AllowAnyHeader().AllowAnyMethod());
            });

            //http://docs.asp.net/en/latest/security/cors.html
            //services.ConfigureCors(options =>
            //{
            //    options.AddPolicy("AllowSpecificOrigin",
            //        builder => builder.WithOrigins("http://example.com"));
            //});

            // Use Ninject to return an instance
            // Create a new Ninject kernel for your bindings
            var kernel = new StandardKernel(new DataModule(Configuration["Data:DataConnection:ConnectionString"]),
                new AutomapperNinjectModule(), new ServicesModule());

            kernel.Populate(services);

            return kernel.Get<IServiceProvider>();
        }
开发者ID:psilon2000,项目名称:LUV,代码行数:39,代码来源:Startup.cs

示例2: ConfigureServices

        public void ConfigureServices(IServiceCollection services)
        {
            services
                .AddMvc()
                .AddJsonOptions(options =>
                    options.SerializerSettings.ContractResolver =
                        new CamelCasePropertyNamesContractResolver()
                );

            services.AddCors();
            services.ConfigureCors(
                cors => cors.AddPolicy("AllowAll",
                    b => b.AllowAnyOrigin().AllowAnyHeader().AllowAnyMethod()
                )
            );

            services.Configure<MvcOptions>(
                options => options.Filters.Add(
                    new CorsAuthorizationFilterFactory("AllowAll")
                )
            );

            services
                .AddEntityFramework()
                .AddInMemoryDatabase()
                .AddDbContext<TodoDbContext>(
                    options => options.UseInMemoryDatabase()
                );
        }
开发者ID:NaseUkolyCZ,项目名称:fsharp-angular,代码行数:29,代码来源:Startup.cs

示例3: ConfigureServices

        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc().Configure<MvcOptions>(options =>
            {
                var jsonFormatter = new JsonOutputFormatter
                {
                    SerializerSettings =
                    {
                        ContractResolver = new CamelCasePropertyNamesContractResolver(),
                        DefaultValueHandling = DefaultValueHandling.Ignore
                    }
                };

                options.OutputFormatters.RemoveTypesOf<JsonOutputFormatter>();
                options.OutputFormatters.Insert(0, jsonFormatter);

            });

            services.AddTransient<IContactsRepository, ContactsRepository>();

            services.ConfigureCors(options =>
            {
                options.AddPolicy(
                    "CorsTutaureliaNet",
                    builder =>
                    {
                        builder.WithOrigins("*").AllowAnyHeader().AllowAnyMethod();
                    });
            });
        }
开发者ID:gobetti,项目名称:ContactsBackEnd,代码行数:30,代码来源:Startup.cs

示例4: ConfigureServices

 public void ConfigureServices(IServiceCollection services)
 {
     services.AddCors();
     services.ConfigureCors(
         options =>
             options.AddPolicy("allowSingleOrigin", builder => builder.WithOrigins("http://example.com")));
 }
开发者ID:Norgerman,项目名称:CORS,代码行数:7,代码来源:Startup.cs

示例5: ConfigureServices

        // This method gets called by a runtime.
        // Use this method to add services to the container
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddInstance<IConfiguration>(Configuration);
            services.AddCustomBindings(Configuration);

            services.AddMvc().Configure<MvcOptions>(options =>
            {
                options.OutputFormatters.OfType<JsonOutputFormatter>()
                       .First()
                       .SerializerSettings
                       .ContractResolver = new CamelCasePropertyNamesContractResolver();
            });

            // CORS
            services.AddCors();

            var policy = new Microsoft.AspNet.Cors.Core.CorsPolicy();
            policy.Headers.Add("*");
            policy.Methods.Add("*");
            policy.Origins.Add("*");
            policy.SupportsCredentials = true;

            services.ConfigureCors(x => x.AddPolicy("mypolicy", policy));

            // Uncomment the following line to add Web API services which makes it easier to port Web API 2 controllers.
            // You will also need to add the Microsoft.AspNet.Mvc.WebApiCompatShim package to the 'dependencies' section of project.json.
            // services.AddWebApiConventions();
        }
开发者ID:RobinVercammen,项目名称:VNextTest,代码行数:30,代码来源:Startup.cs

示例6: ConfigureServices

        // This method gets called by a runtime.
        // Use this method to add services to the container
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc().ConfigureMvc(o=>o.SerializerSettings.ContractResolver=new Newtonsoft.Json.Serialization.CamelCasePropertyNamesContractResolver());
            services.AddCors();

            services.ConfigureCors(o => o.AddPolicy("AllowAll", p => p.AllowAnyOrigin()));
        }
开发者ID:drjofu,项目名称:AureliaMondial,代码行数:9,代码来源:Startup.cs

示例7: ConfigureServices

        // This method gets called by a runtime.
        // Use this method to add services to the container
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddCors();
            services.ConfigureCors(options =>
            {
                options.AddPolicy("AllowSpecificOrigins",
                    builder => builder.WithOrigins("http://localhost:15831")
                                        .AllowAnyHeader()
                                        .AllowAnyMethod()
                                        .AllowCredentials()
                                        .Build());
            });

            //services.AddAuthorization(options =>
            //{
            //    options.AddPolicy("GetTokenClaims",
            //        policy => policy.Requirements.Add(new Karama.Resources.Aspnet5.Controllers.GetTokenClaimsRequirement()));
            //});

            services.AddAuthorization(options =>
            {
                options.AddPolicy("GetTokenClaims",
                    policy => policy.RequireClaim("role", "gettokenclaims"));
            });



            services.AddMvc();
            // Uncomment the following line to add Web API services which makes it easier to port Web API 2 controllers.
            // You will also need to add the Microsoft.AspNet.Mvc.WebApiCompatShim package to the 'dependencies' section of project.json.
            // services.AddWebApiConventions();
        }
开发者ID:darrenschwarz,项目名称:Karama.Identity.Net46,代码行数:34,代码来源:Startup.cs

示例8: ConfigureServices

        // This method gets called by a runtime.
        // Use this method to add services to the container
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc();
            services.AddCors();
            services.ConfigureCors(o => o.AddPolicy("AllowAll", p => p.AllowAnyOrigin()));

            // Uncomment the following line to add Web API services which makes it easier to port Web API 2 controllers.
            // You will also need to add the Microsoft.AspNet.Mvc.WebApiCompatShim package to the 'dependencies' section of project.json.
            // services.AddWebApiConventions();
        }
开发者ID:SimonAspinall9,项目名称:LifeStory,代码行数:12,代码来源:Startup.cs

示例9: ConfigureServices

        public void ConfigureServices(IServiceCollection services)
        {
            services.AddCors();

            services.AddMvc();

            services.ConfigureCors(o =>
            {
                var policy = new CorsPolicy();
                policy.Origins.Add("http://localhost:5001");
                o.AddPolicy("policy1", policy);
            });
        }
开发者ID:kichalla,项目名称:samplecorsapp,代码行数:13,代码来源:Startup.cs

示例10: ConfigureServices

        public void ConfigureServices(IServiceCollection services)
        {
            services.AddCors();

            services.ConfigureCors(options =>
            {
                options.AddPolicy("Cors",
                    builder => builder
                        .WithOrigins( "http://localhost:33654", "http://localhost:2000")
                        .WithHeaders( "accept", "content-type", "origin", "x-custom-header")
                        .WithMethods("GET", "POST", "PUT", "DELETE"));
            });

            services.AddMvc();
        }
开发者ID:gabrielladeira,项目名称:workbox,代码行数:15,代码来源:Startup.cs

示例11: ConfigureServices

        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc();
            services.ConfigureCors(options =>
            {
                // Define one or more CORS policies
                options.AddPolicy("AllowSpecificOrigin",
                    builder =>
                    {
                        builder.WithOrigins("http://example.com");
                    });
            });

            services.Configure<MvcOptions>(options =>
            {
                options.Filters.Add(new CorsAuthorizationFilterFactory("AllowSpecificOrigin"));
            });
        }
开发者ID:bigfont,项目名称:Docs,代码行数:18,代码来源:Startup.cs

示例12: ConfigureServices

        // This method gets called by a runtime.
        // Use this method to add services to the container
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc();

            // Uncomment the following line to add Web API services which makes it easier to port Web API 2 controllers.
            // You will also need to add the Microsoft.AspNet.Mvc.WebApiCompatShim package to the 'dependencies' section of project.json.
            // services.AddWebApiConventions();
            services.AddCors();

            var policy = new Microsoft.AspNet.Cors.Core.CorsPolicy();

            policy.Headers.Add("*");
            policy.Methods.Add("*");
            policy.Origins.Add("*");
            policy.SupportsCredentials = true;

            services.ConfigureCors(x => x.AddPolicy("mypolicy", policy));
        }
开发者ID:djturner1984,项目名称:vs-2015-angular-sass,代码行数:20,代码来源:Startup.cs

示例13: ConfigureServices

 // For more information on how to configure your application, visit http://go.microsoft.com/fwlink/?LinkID=398940
 public void ConfigureServices(IServiceCollection services)
 {
     services.AddCors();
     services.ConfigureCors(options =>
                             options.AddPolicy("AllowAll", p => p.AllowAnyOrigin()
                                                                 .AllowAnyMethod()
                                                                 .AllowAnyHeader()));
     services.AddMvc();
     services.AddSwagger(c =>
     {
         c.SwaggerGeneratorOptions.SingleApiVersion(new Info
         {
             Version = "v1",
             Title = "Huzzah!",
             Description = "An example ASP.NET 5 service",
             TermsOfService = "Unintelligible legalese..."
         });
     });
 }
开发者ID:rzachariah,项目名称:hello-aspnet5,代码行数:20,代码来源:Startup.cs

示例14: ConfigureServices

        // This method gets called by a runtime.
        // Use this method to add services to the container
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddTransient<MrUserAccountService, MrUserAccountService>();
            services.AddTransient<MrConfig, MrConfig>();
            services.AddTransient<MrUserRepository, MrUserRepository>();
            services.AddTransient<MrDatabase, MrDatabase>();

            services.AddCors();
            services.ConfigureCors(options =>
            {
                options.AddPolicy("AllowSpecificOrigins",
                    builder => builder.WithOrigins("http://localhost:15831", "http://localhost:15832")
                        .AllowAnyHeader()
                        .AllowAnyMethod()
                        .AllowCredentials()
                        .Build());
            });
            services.AddMvc();
        }
开发者ID:darrenschwarz,项目名称:Karama.Identity.Net46,代码行数:21,代码来源:TestStartupConfiguration.cs

示例15: ConfigureServices

        public void ConfigureServices(IServiceCollection services)
        {
            services.Configure<AppSettings>(Configuration.GetConfigurationSection("AppSettings"));

            // Add EF services to the services container
            services.AddEntityFramework()
                    .AddSqlServer()
                    .AddDbContext<MusicStoreContext>(options =>
                            options.UseSqlServer(Configuration.Get("Data:DefaultConnection:ConnectionString")));

            services.ConfigureCors(options =>
            {
                options.AddPolicy("CorsPolicy", builder =>
                {
                    builder.WithOrigins("http://example.com");
                });
            });

            // Add MVC services to the services container
            services.AddMvc();

            //Add all SignalR related services to IoC.
            services.AddSignalR();

            //Add InMemoryCache
            services.AddSingleton<IMemoryCache, MemoryCache>();

            // Add session related services.
            services.AddCaching();
            services.AddSession();

            // Add the system clock service
            services.AddSingleton<ISystemClock, SystemClock>();

            // Configure Auth
            services.Configure<AuthorizationOptions>(options =>
            {
                options.AddPolicy("ManageStore", new AuthorizationPolicyBuilder().RequireClaim("ManageStore", "Allowed").Build());
            });
        }
开发者ID:joerter,项目名称:MusicStore,代码行数:40,代码来源:StartupNtlmAuthentication.cs


注:本文中的IServiceCollection.ConfigureCors方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。