.net core allowing cross-domain

// set all sources to allow cross-domain 
app.UseCors (Options => 
{ 
       options.AllowAnyHeader (); 
       options.AllowAnyMethod (); 
       options.AllowAnyOrigin (); 
       options.AllowCredentials (); 
}); 

// set to allow only a specific source cross-domain 
app.UseCors (Options => 
{ 
        options.WithOrigins ( " HTTP: // localhost: 3000 " , " of http://127.0.0.1 " ); // allow cross-domain specific ip 
        options.AllowAnyHeader (); 
        Options .AllowAnyMethod (); 
        options.AllowCredentials (); 
});

In the method of Startup.cs Configure the following code is added, pro-test Haoshi:

        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            // 设置允许所有来源跨域
            app.UseCors(options =>
            {
                options.AllowAnyHeader();
                options.AllowAnyMethod();
                options.AllowAnyOrigin();
                options.AllowCredentials();
            });

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
                app.UseHsts();
            }

            app.UseHttpsRedirection();
            app.UseMvc();
        }

 

Guess you like

Origin www.cnblogs.com/xtjatswc/p/11303811.html