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


C# IAppBuilder.UseCors方法代码示例

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


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

示例1: Configuration

        public void Configuration(IAppBuilder app)
        {
            //var issuer = ConfigurationManager.AppSettings["jwtIssuer"];
            //var audience = ConfigurationManager.AppSettings["jwtClientId"];
            //var jwtKey = TextEncodings.Base64.Decode(ConfigurationManager.AppSettings["jwtVerificationKey"]);
            //var authOptions = new JwtBearerAuthenticationOptions
            //{
            //    AuthenticationMode = AuthenticationMode.Active,
            //    AllowedAudiences = new[] { audience },
            //    IssuerSecurityTokenProviders = new IIssuerSecurityTokenProvider[]
            //    {
            //        new X509CertificateSecurityTokenProvider(issuer, new X509Certificate2(jwtKey)), 
            //    }
            //};
            //app.UseJwtBearerAuthentication(authOptions);

            var config = new HttpConfiguration();
            Bootstrapper.InstallDatabase();
            Bootstrapper.StartWith(config);

            var allowedOrigin = ConfigurationManager.AppSettings["allowOrigin"];
            if (allowedOrigin != "*")
            {
                var policy = new CorsPolicy
                {
                    AllowAnyHeader = true,
                    AllowAnyMethod = true,
                    SupportsCredentials = true,
                };

                if (allowedOrigin.EndsWith("/")) allowedOrigin = allowedOrigin.Substring(0, allowedOrigin.Length - 1);

                policy.Origins.Add(allowedOrigin);
                app.UseCors(new CorsOptions
                {
                    PolicyProvider = new CorsPolicyProvider
                    {
                        PolicyResolver = context => Task.FromResult(policy)
                    },
                    CorsEngine = new SubdomainsAcceptingCorsEngine()
                });
            }
            else
            {
                app.UseCors(CorsOptions.AllowAll);
            }
            app.UseWebApi(config);
        }
开发者ID:teledu,项目名称:MoManI,代码行数:48,代码来源:Startup.cs

示例2: Configuration

        public void Configuration(IAppBuilder app)
        {
            var policy = new CorsPolicy
            {
                AllowAnyHeader = true,
                AllowAnyMethod = true,
                SupportsCredentials = true
            };

            policy.ExposedHeaders.Add("Authorization");

            app.UseCors(new CorsOptions
            {
                PolicyProvider = new CorsPolicyProvider
                {
                    PolicyResolver = context => Task.FromResult(policy)
                }
            });

            var config = new HttpConfiguration();

            WebApiConfig.Register(config);

            app.UseNinjectMiddleware(CreateKernel);
            app.UseNinjectWebApi(config);

        }
开发者ID:IbrahimAmin,项目名称:MR-Reporting-System,代码行数:27,代码来源:Startup.cs

示例3: Configuration

        public void Configuration(IAppBuilder app)
        {
            //log4net.Config.XmlConfigurator.Configure();

            var bootstrapper = new Bootstrapper();
            var container = bootstrapper.Build();
            var priceFeed = container.Resolve<IPriceFeed>();
            priceFeed.Start();
            var cleaner = container.Resolve<Cleaner>();
            cleaner.Start();

            app.UseCors(CorsOptions.AllowAll);
            app.Map("/signalr", map =>
            {
                var hubConfiguration = new HubConfiguration
                {
                    // you don't want to use that in prod, just when debugging
                    EnableDetailedErrors = true,
                    EnableJSONP = true,
                    Resolver = new AutofacSignalRDependencyResolver(container)
                };

                map.UseCors(CorsOptions.AllowAll)
                    .RunSignalR(hubConfiguration);
            });
        }
开发者ID:dancingchrissit,项目名称:ReactiveTrader,代码行数:26,代码来源:Startup.cs

示例4: Configuration

        public void Configuration(IAppBuilder app)
        {
            // initialize cors
            app.UseCors(CorsOptions.AllowAll);

            // initialize authentication
            app.UseCookieAuthentication(new CookieAuthenticationOptions()
            {
                AuthenticationType = CookieAuthenticationDefaults.AuthenticationType,
                AuthenticationMode = AuthenticationMode.Active,
                ExpireTimeSpan = TimeSpan.FromHours(1),
                SlidingExpiration = true                
            });

            // initialize webapi
            HttpConfiguration config = new HttpConfiguration();
            config.MapHttpAttributeRoutes();
            config.Routes.MapHttpRoute(
                name: "Default",
                routeTemplate: "{controller}/{id}",
                defaults: new 
                { 
                    id = RouteParameter.Optional 
                });

            // initialize dependency injection
            ConfigureDependencies(app, config);

            // bind web api
            app.UseWebApi(config);
        }
开发者ID:nascentdigital,项目名称:web-template,代码行数:31,代码来源:Startup.cs

示例5: Configuration

 // This method is required by Katana:
 public void Configuration(IAppBuilder app)
 {
     var webApiConfiguration = ConfigureWebApi();
     
     app.UseCors(CorsOptions.AllowAll);            
     app.UseWebApi(webApiConfiguration);
 }
开发者ID:valpioner,项目名称:Ukrland,代码行数:8,代码来源:Startup.cs

示例6: Configuration

        public void Configuration(IAppBuilder app)
        {
            app.UseCors(CorsOptions.AllowAll);

            ConfigureAuth(app);
            app.UseNinjectMiddleware(CreateKernel).UseNinjectWebApi(GlobalConfiguration.Configuration);
        }
开发者ID:GeorgiNik,项目名称:TelerikAcademy,代码行数:7,代码来源:Startup.cs

示例7: Configuration

        public void Configuration(IAppBuilder app)
        {
            // This must come first to intercept the /Token requests
            app.UseCors(CorsOptions.AllowAll);

            ConfigureAuth(app);
        }
开发者ID:FranPaz,项目名称:CFenix,代码行数:7,代码来源:Startup.cs

示例8: ConfigureAuth

        public void ConfigureAuth(IAppBuilder app)
        {
            OAuthAuthorizationServerOptions OAuthServerOptions = new OAuthAuthorizationServerOptions()
            {
                AuthenticationType = Constant.GrantTypes.AuthenticationType,
                AllowInsecureHttp = true,
                TokenEndpointPath = new PathString(WebConfig.TokenPath),
                AccessTokenExpireTimeSpan = TimeSpan.FromSeconds(int.Parse(WebConfig.AccessTokenExpireTimeSpan)),
                Provider = new OAuth2AuthorizationServerProvider(),
                RefreshTokenProvider = new OAuth2RefreshTokenProvider()
            };
            //AuthenticationType :认证类型
            //AllowInsecureHttp : 如果允许客户端的 return_uri 参数不是 HTTPS 地址, 则设置为 true
            //TokenEndpointPath : 客户端应用可以直接访问并得到访问令牌的地址, 必须以前倒斜杠 "/" 开始, 例如: /Token
            //AccessTokenExpireTimeSpan :Token过期时间
            //Provider : 应用程序提供和 OAuth 认证中间件交互的 IOAuthAuthorizationServerProvider 实例, 通常可以使用默认的
            //OAuthAuthorizationServerProvider , 并设置委托函数即可
            //RefreshTokenProvider :刷新令牌, 如果这个属性没有设置, 则不能从 /Token 刷新令牌

            // 令牌生成
            app.UseOAuthAuthorizationServer(OAuthServerOptions);

            app.UseOAuthBearerAuthentication(new OAuthBearerAuthenticationOptions());

            //跨域处理
            app.UseCors(CorsOptions.AllowAll);
        }
开发者ID:doscanner,项目名称:GF,代码行数:27,代码来源:Startup.Auth.cs

示例9: Configuration

        public void Configuration(IAppBuilder app)
        {
            app.UseCors(Microsoft.Owin.Cors.CorsOptions.AllowAll);
            ConfigureAuth(app);

            var config = new HttpConfiguration();

            config.DependencyResolver = new NinjectResolver((new Bootstrapper()).Kernel);

            config.SuppressDefaultHostAuthentication();
            config.Filters.Add(new HostAuthenticationFilter(OAuthDefaults.AuthenticationType));

            config.MapHttpAttributeRoutes();

            config.Routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "api/{controller}/{id}",
                defaults: new { id = RouteParameter.Optional }
            );

            var formatters = config.Formatters;
            var jsonFormatter = formatters.JsonFormatter;
            var settings = jsonFormatter.SerializerSettings;
            settings.Formatting = Formatting.Indented;
            settings.ContractResolver = new CamelCasePropertyNamesContractResolver();

            app.UseWebApi(config);
        }
开发者ID:isimic413,项目名称:OnlineExamPrep,代码行数:28,代码来源:Startup.cs

示例10: Configuration

        public static void Configuration(IAppBuilder app)
        {
            app.UseCors(Microsoft.Owin.Cors.CorsOptions.AllowAll);

            var OAuthOptions = new OAuthAuthorizationServerOptions
            {
                AllowInsecureHttp = true,
                TokenEndpointPath = new PathString("/oauth/Token"),
                AccessTokenExpireTimeSpan = TimeSpan.FromHours(8),
                Provider = new Providers.MyAuthorizationServerProvider(),
                // RefreshTokenProvider = new Providers.MyRefreshTokenProvider(DateTime.UtcNow.AddHours(8))
            };
            app.UseOAuthAuthorizationServer(OAuthOptions);
            app.UseOAuthBearerAuthentication(new OAuthBearerAuthenticationOptions());

            // Configure Web API for self-host.
            HttpConfiguration config = new HttpConfiguration();

            config.SuppressDefaultHostAuthentication();
            config.Filters.Add(new HostAuthenticationFilter(OAuthDefaults.AuthenticationType));

            // Web API routes
            config.MapHttpAttributeRoutes();

            // We don't need this crap anymore!
            //config.Routes.MapHttpRoute(
            //    name: "DefaultApi",
            //    routeTemplate: "api/{controller}/{id}",
            //    defaults: new { id = RouteParameter.Optional }
            //);

            app.UseWebApi(config);
        }
开发者ID:wyerp,项目名称:OwinWebApiBearerToken,代码行数:33,代码来源:Startup.cs

示例11: Configuration

 public void Configuration(IAppBuilder app)
 {
     var configuration = new HubConfiguration();
     configuration.EnableDetailedErrors = true;
     app.UseCors(CorsOptions.AllowAll);
     app.MapSignalR(configuration);
 }
开发者ID:vtesin,项目名称:Levi9-GeoTagging,代码行数:7,代码来源:Startup.cs

示例12: Configuration

        public void Configuration(IAppBuilder app)
        {
           
            // token validation
            app.UseIdentityServerBearerTokenAuthentication(new IdentityServerBearerTokenAuthenticationOptions
            {
                Authority = Constants.IdentityServerUri,
                RequiredScopes = new[] { "apiAccess" }
            });

            // add app local claims per request
            app.UseClaimsTransformation(incoming =>
            {
                // either add claims to incoming, or create new principal
                var appPrincipal = new ClaimsPrincipal(incoming);
                incoming.Identities.First().AddClaim(new Claim("appSpecific", "some_value"));

                return Task.FromResult(appPrincipal);
            });

            app.UseCors(CorsOptions.AllowAll);

            var config = new HttpConfiguration();
            config.MapHttpAttributeRoutes();
            // web api configuration
            app.UseWebApi(config);
        }
开发者ID:mcginkel,项目名称:identityServer3Example,代码行数:27,代码来源:Startup.cs

示例13: Configuration

        public void Configuration(IAppBuilder app)
        {
            app.UseCors(CorsOptions.AllowAll);
            app.RunSignalR();

            XmlConfigurator.Configure();
        }
开发者ID:AcklenAvenue,项目名称:Pepino,代码行数:7,代码来源:Startup.cs

示例14: ConfigureCors

        public void ConfigureCors(IAppBuilder app)
        {
            app.Use(async (context, next) =>
            {
                var req = context.Request;
                var res = context.Response;

                if (req.Method == "OPTIONS")
                {
                    res.StatusCode = 200;
                    res.Headers.AppendCommaSeparatedValues(CorsConstants.AccessControlAllowMethods, "GET", "POST", "PUT",
                        "DELETE");

                    res.Headers.AppendCommaSeparatedValues(CorsConstants.AccessControlAllowHeaders, "accept",
                        "authorization", "content-type", "x-api-applicationid", "access-control-allow-origin", "cache-control", "x-requested-with");

                    var headerValues = req.Headers.GetValues("Origin");
                    var origin = headerValues?.FirstOrDefault();
                    if (origin != null)
                    {
                        res.Headers.Append(CorsConstants.AccessControlAllowOrigin, origin);
                    }

                    return;
                }

                await next();
            });

            app.UseCors(CorsOptions.AllowAll);
        }
开发者ID:eddievagabond,项目名称:angular-oauth-base,代码行数:31,代码来源:Startup.Cors.cs

示例15: ConfigureAuth

        public void ConfigureAuth(IAppBuilder app)
        {
            app.CreatePerOwinContext(() => new EnergyNetworkDbContext());
              app.CreatePerOwinContext<ApplicationUserManager>(ApplicationUserManager.Create);
              app.CreatePerOwinContext<ApplicationRoleManager>(ApplicationRoleManager.Create);

              //Enable Cors support in the Web API. Should go before the activation of Bearer tokens
              //http://aspnetwebstack.codeplex.com/discussions/467315
              app.UseCors(CorsOptions.AllowAll);

              app.UseCookieAuthentication(new CookieAuthenticationOptions());

              app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);

              // Enable the application to use bearer tokens to authenticate users
              // Enabling 3 components:
              // 1. Authorization Server middleware. For creating the bearer tokens
              // 2. Application bearer token middleware. Will atuthenticate every request with Authorization : Bearer header
              // 3. External bearer token middleware. For external providers
              app.UseOAuthBearerTokens(OAuthOptions);

              app.UseMicrosoftAccountAuthentication(ConfigurationManager.AppSettings["MicrosoftKey"],
            ConfigurationManager.AppSettings["MicrosoftSecret"]);

              app.UseTwitterAuthentication(ConfigurationManager.AppSettings["TwitterKey"],
            ConfigurationManager.AppSettings["TwitterSecret"]);

              app.UseFacebookAuthentication(ConfigurationManager.AppSettings["FacebookKey"],
            ConfigurationManager.AppSettings["FacebookSecret"]);

              app.UseGoogleAuthentication();
        }
开发者ID:htw-bui,项目名称:EnergieNetz,代码行数:32,代码来源:Startup.Auth.cs


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