Skip to content

Commit 870a667

Browse files
committed
更新WebApi
1 parent 34c675a commit 870a667

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

Sample/Senparc.CO2NET.Sample.net6/Startup.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public void ConfigureServices(IServiceCollection services)
5757
WebApi.Register.AdditionalMethods.Add(typeof(EncryptHelper).GetMethod("GetMD5", new[] { typeof(string), typeof(string) }), "Additional");
5858

5959
var docXmlPath = Path.Combine(WebHostEnvironment.ContentRootPath, "App_Data", "ApiDocXml");
60-
services.AddAndInitDynamicApi(builder, docXmlPath, ApiRequestMethod.Get, null, 400, false, true, m => null);
60+
services.AddAndInitDynamicApi(builder, docXmlPath, ApiRequestMethod.Get, null, 400, false, true, m => null, forbiddenExternalAccess: true);
6161

6262
#endregion
6363

@@ -90,7 +90,7 @@ public void ConfigureServices(IServiceCollection services)
9090
// Name = "Apache License Version 2.0",
9191
// Url = new Uri("https://github.com/JeffreySu/WeiXinMPSDK")
9292
//},
93-
93+
9494
Contact = new OpenApiContact()
9595
{
9696
Email = "zsu@senparc.com",

src/Senparc.CO2NET.AspNet/Extensions/HttpExtensions.cs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,35 @@ public static bool IsLocal(this HttpRequest req)
7676
return true;
7777
}
7878

79+
///// <summary>
80+
///// 是否是本地请求
81+
///// </summary>
82+
///// <param name="req"></param>
83+
///// <returns></returns>
84+
//public static bool IsLocal(this HttpRequest req)
85+
//{
86+
// var connection = req.HttpContext.Connection;
87+
// if (connection.RemoteIpAddress != null)
88+
// {
89+
// if (connection.LocalIpAddress != null)
90+
// {
91+
// return connection.RemoteIpAddress.Equals(connection.LocalIpAddress);
92+
// }
93+
// else
94+
// {
95+
// return IPAddress.IsLoopback(connection.RemoteIpAddress);
96+
// }
97+
// }
98+
99+
// // for in memory TestServer or when dealing with default connection info
100+
// if (connection.RemoteIpAddress == null && connection.LocalIpAddress == null)
101+
// {
102+
// return true;
103+
// }
104+
105+
// return false;
106+
//}
107+
79108
private static bool IsSet(this IPAddress address)
80109
{
81110
return address != null && address.ToString() != NullIpAddress;
@@ -176,6 +205,8 @@ public static IPAddress UserHostAddress(this HttpContext httpContext)
176205
{
177206
return httpContext.Features.Get<IHttpConnectionFeature>()?.RemoteIpAddress;
178207
}
208+
209+
179210
}
180211
}
181212
#endif

0 commit comments

Comments
 (0)