|
|
@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
using Microsoft.AspNetCore.Cors;
|
|
|
|
|
|
|
|
using Microsoft.AspNetCore.Http;
|
|
|
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace CorsServer.WebApi31.Controllers
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
[Route("api/[controller]/[action]")]
|
|
|
|
|
|
|
|
[ApiController]
|
|
|
|
|
|
|
|
public class CorsController : ControllerBase
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
public CorsController()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[HttpGet]
|
|
|
|
|
|
|
|
[HttpOptions]
|
|
|
|
|
|
|
|
public IActionResult Ping()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var data = new { Code=0, Messge="全局跨域策略"};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return Ok(data);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
[HttpGet]
|
|
|
|
|
|
|
|
[HttpOptions]
|
|
|
|
|
|
|
|
[EnableCors(Startup.CorsName)]
|
|
|
|
|
|
|
|
public IActionResult HasCors()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var data = new { Code = 0, Messge = "单独明确可以跨域" };
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return Ok(data);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[HttpGet]
|
|
|
|
|
|
|
|
[HttpOptions]
|
|
|
|
|
|
|
|
public IActionResult NoCors()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var data = new { Code = 0, Messge = "不允许跨域" };
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return Ok(data);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|