Skip to content

Commit 1d65091

Browse files
author
PHAN Xuan Quang
committed
cors fix
1 parent 5d87dff commit 1d65091

File tree

1 file changed

+41
-41
lines changed

1 file changed

+41
-41
lines changed

EngAce.Api/Program.cs

+41-41
Original file line numberDiff line numberDiff line change
@@ -84,56 +84,56 @@
8484
options.Level = System.IO.Compression.CompressionLevel.Fastest;
8585
});
8686

87-
builder.Services.AddCors(options =>
88-
{
89-
options.AddPolicy("AllowOnlyEngace",
90-
policy =>
91-
{
92-
policy.WithOrigins(allowedOrigin, "117.1.167.81")
93-
.AllowAnyMethod()
94-
.AllowAnyHeader();
95-
});
96-
}); ;
87+
//builder.Services.AddCors(options =>
88+
//{
89+
// options.AddPolicy("AllowOnlyEngace",
90+
// policy =>
91+
// {
92+
// policy.WithOrigins(allowedOrigin, "117.1.167.81")
93+
// .AllowAnyMethod()
94+
// .AllowAnyHeader();
95+
// });
96+
//});
9797

9898
builder.Services.AddResponseCaching();
9999

100100
var app = builder.Build();
101101

102102
app.UseDeveloperExceptionPage();
103-
104-
if (app.Environment.IsDevelopment())
105-
{
106-
app.UseSwagger();
107-
app.UseSwaggerUI(c =>
108-
{
109-
c.SwaggerEndpoint("/swagger/v1/swagger.json", "Backend APIs");
110-
});
111-
}
112-
113103
app.UseHttpsRedirection();
114104
app.UseRouting();
115105

116-
if(!app.Environment.IsDevelopment())
117-
{
118-
app.Use(async (context, next) =>
119-
{
120-
var allowedIP = "117.1.167.81";
121-
122-
var origin = context.Request.Headers.Origin.ToString();
123-
var remoteIp = context.Connection.RemoteIpAddress?.ToString();
124-
125-
if ((string.IsNullOrEmpty(origin) || origin != allowedOrigin) && remoteIp != allowedIP)
126-
{
127-
context.Response.StatusCode = StatusCodes.Status403Forbidden;
128-
await context.Response.WriteAsync("Access Denied.");
129-
return;
130-
}
131-
132-
await next();
133-
});
134-
135-
app.UseCors("AllowOnlyEngace");
136-
}
106+
//if (app.Environment.IsDevelopment())
107+
//{
108+
// app.UseSwagger();
109+
// app.UseSwaggerUI(c =>
110+
// {
111+
// c.SwaggerEndpoint("/swagger/v1/swagger.json", "Backend APIs");
112+
// });
113+
//}
114+
115+
116+
//if(!app.Environment.IsDevelopment())
117+
//{
118+
// app.Use(async (context, next) =>
119+
// {
120+
// var allowedIP = "117.1.167.81";
121+
122+
// var origin = context.Request.Headers.Origin.ToString();
123+
// var remoteIp = context.Connection.RemoteIpAddress?.ToString();
124+
125+
// if ((string.IsNullOrEmpty(origin) || origin != allowedOrigin) && remoteIp != allowedIP)
126+
// {
127+
// context.Response.StatusCode = StatusCodes.Status403Forbidden;
128+
// await context.Response.WriteAsync("Access Denied.");
129+
// return;
130+
// }
131+
132+
// await next();
133+
// });
134+
135+
// app.UseCors("AllowOnlyEngace");
136+
//}
137137

138138
app.UseResponseCompression();
139139

0 commit comments

Comments
 (0)