origin
HTTP μμ² ν€λκ° μ§μ λμ§ μμ CORS μ¬μ© λμ μ HTTP μμ²μ΄ μνλλ©΄ HTTP 500 μ€λ₯μ ν¨κ» μμ²μ΄ μ€ν¨ν©λλ€.
λ‘κ·Έμ μμΈλ λ€μκ³Ό κ°μ΅λλ€.
[2019-04-13 14:40:04Z] fail: Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware[1]
An unhandled exception has occurred while executing the request.
System.InvalidOperationException: Endpoint MartinCostello.Api.Controllers.TimeController.Get (API) contains CORS metadata, but a middleware was not found that supports CORS.
Configure your application startup by adding app.UseCors() inside the call to Configure(..) in the application startup code.
at Microsoft.AspNetCore.Routing.EndpointMiddleware.ThrowMissingCorsMiddlewareException(Endpoint endpoint)
at Microsoft.AspNetCore.Routing.EndpointMiddleware.Invoke(HttpContext httpContext)
at Microsoft.AspNetCore.Routing.EndpointRoutingMiddleware.Invoke(HttpContext httpContext)
at Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.HttpOverrides.HttpMethodOverrideMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)
κ·Έλ¬λ app.Cors()
_has_μ΄ (κ°) app.UseEndpoints(...)
μ΄μ μ μ ν리μΌμ΄μ
μ μΆκ°λμμ΅λλ€.
μ΄κ²μ # 9181μ μν΄ λμ λ κ²μΌλ‘ 보μ λλ€.
μμ²μ origin
μμ² ν€λκ°μλ κ²½μ° CORS λ―Έλ€μ¨μ΄λ₯Ό 건λ λλλ€.
κ·Έλ¬λ μλ ν¬μΈνΈ λ―Έλ€μ¨μ΄λ νΈμΆλλ μλ ν¬μΈνΈμμ CORS λ©ν λ°μ΄ν°λ₯Ό μ°Ύκ³ , HttpContext
μ ν€λ₯Ό μ°Ύμ CORS λ―Έλ€μ¨μ΄κ° νΈμΆλμλμ§ (νμνμ§ μμ κ²μΌλ‘ 건λ λ°μλμ§) νμΈν©λλ€. νλͺ©. νλͺ©μ΄ μμΌλ―λ‘ μμΈκ° λ°μν©λλ€.
μλ ν¬μΈνΈ λ―Έλ€μ¨μ΄μμ ν
μ€νΈμ€μΈ ν€λ origin
ν€λκ° μμ²μμλ κ²½μ°μλ§ μΆκ°λ©λλ€.
λ κ°μ§ κ°λ₯ν μμ μ¬νμ λ€μκ³Ό κ°μ΅λλ€.
HttpContext.Items
μ μΆκ°ν©λλ€. λλ :origin
ν€λλ₯Ό νμΈνκ³ HTTP μμ²μμλ κ²½μ° CORS λ―Έλ€μ¨μ΄μ λΉ νΈμΆμ λν μμΈ λ§ λ°μν©λλ€.[EnableCors(...)]
μμ±μ μΆκ°ν©λλ€.origin
HTTP μμ² ν€λκ° μ 곡λμ§ μμΌλ©΄ μμ²μ΄ μ±κ³΅ν©λλ€.
.NET Core SDK (reflecting any global.json):
Version: 3.0.100-preview4-011204
Commit: 621575bab1
Runtime Environment:
OS Name: Windows
OS Version: 10.0.17763
OS Platform: Windows
RID: win10-x64
Base Path: C:\Program Files\dotnet\sdk\3.0.100-preview4-011204\
Host (useful for support):
Version: 3.0.0-preview4-27612-09
Commit: 64e9c3e1cd
κ°λ¨ν μλ λ°μ€ μ±μ λνμ΄ μ»€λ°μ λ§λλ κ³Όμ μμ λ¬Έμ κ° λ°κ²¬λμμ΅λλ€. https://github.com/martincostello/api/pull/109/commits/a40a99f2dbb82d17ce6cc7cde5e13bc400d78137
cc @pranavkm
preview4μ κ²½μ° κ°λ₯ν ν΄κ²° λ°©λ²μ λ€μκ³Ό κ°μ΅λλ€.
1) λ―Έλ€μ¨μ΄λ₯Ό κ°λ μΈνΈμ κ° HttpContext.Items
ν UseCors()
```C #
app.UseCors ();
app.Use ((λ¬Έλ§₯, λ€μ) =>
{
context.Items [ "__ CorsMiddlewareInvoked"] = true;
return next ();
});
2) Disable the check in `EndpointRouting`:
```C#
services.AddRouting(r => r.SuppressCheckForUnhandledSecurityMetadata = true);
첫 λ²μ§Έλ μλͺ» ꡬμ±λ μμ© νλ‘κ·Έλ¨μ λν κ²μ¬λ₯Ό μ κ±°νμ§ μκΈ° λλ¬Έμ μ νΈλ©λλ€.
κ°μ₯ μ μ©ν λκΈ
preview4μ κ²½μ° κ°λ₯ν ν΄κ²° λ°©λ²μ λ€μκ³Ό κ°μ΅λλ€.
1) λ―Έλ€μ¨μ΄λ₯Ό κ°λ μΈνΈμ κ°
HttpContext.Items
νUseCors()
```C #
app.UseCors ();
app.Use ((λ¬Έλ§₯, λ€μ) =>
{
context.Items [ "__ CorsMiddlewareInvoked"] = true;
return next ();
});
첫 λ²μ§Έλ μλͺ» ꡬμ±λ μμ© νλ‘κ·Έλ¨μ λν κ²μ¬λ₯Ό μ κ±°νμ§ μκΈ° λλ¬Έμ μ νΈλ©λλ€.