Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 486a035

Browse files
committed
#跨域问题#
1 parent 54e893e commit 486a035

File tree

8 files changed

+39
-33
lines changed

8 files changed

+39
-33
lines changed

‎APIJSON.NET/APIJSON.NET/APIJSON.NET.csproj

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<Project Sdk="Microsoft.NET.Sdk.Web">
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
22

33
<PropertyGroup>
44
<TargetFramework>netcoreapp2.1</TargetFramework>
@@ -16,10 +16,16 @@
1616

1717
<ItemGroup>
1818
<PackageReference Include="AspectCore.Extensions.Reflection" Version="0.7.0" />
19-
<PackageReference Include="Microsoft.AspNetCore.App" />
19+
<PackageReference Include="Microsoft.AspNetCore.App" Version="2.1.2"/>
2020
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="2.1.1" />
21+
<PackageReference Include="Microsoft.AspNetCore.Cors" Version="2.1.1" />
22+
<PackageReference Include="Microsoft.AspNetCore.Rewrite" Version="2.1.1" />
23+
<PackageReference Include="Microsoft.AspNetCore.Server.Kestrel.Https" Version="2.1.2" />
2124
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.1.0" />
2225
<PackageReference Include="MySql.Data" Version="8.0.11" />
26+
<PackageReference Include="Oracle.ManagedDataAccess.Core" Version="2.12.0-beta3" />
27+
<PackageReference Include="SqlKata" Version="1.0.4" />
28+
<PackageReference Include="SqlKata.Execution" Version="1.0.4" />
2329
<PackageReference Include="sqlSugarCore" Version="4.6.4.9" />
2430
<PackageReference Include="Swashbuckle.AspNetCore" Version="3.0.0" />
2531
<PackageReference Include="Swashbuckle.AspNetCore.Annotations" Version="3.0.0" />

‎APIJSON.NET/APIJSON.NET/Controllers/JsonController.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@
1111
using System.Linq;
1212
using APIJSON.NET.Services;
1313
using System.Reflection;
14+
using Microsoft.AspNetCore.Cors;
1415

1516
[Route("api/[controller]")]
1617
[ApiController]
18+
[EnableCors("localhost")]
1719
public class JsonController : ControllerBase
1820
{
1921

‎APIJSON.NET/APIJSON.NET/Controllers/TokenController.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using System.Text;
88
using System.Threading.Tasks;
99
using Microsoft.AspNetCore.Authorization;
10+
using Microsoft.AspNetCore.Cors;
1011
using Microsoft.AspNetCore.Http;
1112
using Microsoft.AspNetCore.Mvc;
1213
using Microsoft.Extensions.Options;
@@ -17,6 +18,7 @@ namespace APIJSON.NET.Controllers
1718
[Route("api/[controller]/[action]")]
1819
[ApiController]
1920
[Authorize]
21+
[EnableCors("localhost")]
2022
public class TokenController : ControllerBase
2123
{
2224
private DbContext db;
@@ -28,7 +30,7 @@ public TokenController(DbContext _db, IOptions<TokenAuthConfiguration> configura
2830
}
2931
[HttpPost("/token")]
3032
[AllowAnonymous]
31-
public IActionResult Create([FromBody]TokenInput input)
33+
public ActionResult Create([FromBody]TokenInput input)
3234
{
3335
JObject ht = new JObject();
3436
ht.Add("code", "200");
@@ -72,7 +74,7 @@ public IActionResult Create([FromBody]TokenInput input)
7274
return Ok(ht);
7375
}
7476
[HttpGet]
75-
public IActionResult GetRole()
77+
public ActionResult GetRole()
7678
{
7779
return Ok(User.FindFirstValue(ClaimTypes.Role));
7880
}

‎APIJSON.NET/APIJSON.NET/Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
FROM microsoft/aspnetcore:latest
1+
FROM microsoft/dotnet:2.1.2-aspnetcore-runtime
22

33
WORKDIR /app
44
COPY . .
55

6+
67
ENTRYPOINT ["dotnet", "APIJSON.NET.dll"]

‎APIJSON.NET/APIJSON.NET/Program.cs

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.IO;
4-
using System.Linq;
5-
using System.Threading.Tasks;
6-
using Microsoft.AspNetCore;
1+
using Microsoft.AspNetCore;
72
using Microsoft.AspNetCore.Hosting;
8-
using Microsoft.Extensions.Configuration;
9-
using Microsoft.Extensions.Logging;
3+
using System.Net;
104

115
namespace APIJSON.NET
126
{
@@ -17,8 +11,9 @@ public static void Main(string[] args)
1711
CreateWebHostBuilder(args).Build().Run();
1812
}
1913

20-
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
21-
WebHost.CreateDefaultBuilder(args)
22-
.UseStartup<Startup>();
14+
public static IWebHostBuilder CreateWebHostBuilder(string[] args)
15+
{
16+
return WebHost.CreateDefaultBuilder(args).UseStartup<Startup>();
17+
}
2318
}
2419
}

‎APIJSON.NET/APIJSON.NET/SelectTable.cs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,6 @@ public object ExecFunc(string funcname,object[] param, Type[] types)
5454

5555
var reflector = method.GetReflector();
5656
var result = reflector.Invoke(new FuncList(), param);
57-
//Type type = typeof(FuncList);
58-
//Object obj = Activator.CreateInstance(type);
59-
//MethodInfo mt = type.GetMethod(funcname,types);
60-
//if (mt==null)
61-
//{
62-
// throw new Exception($"{funcname}没有获取到相应的函数");
63-
//}
64-
//return mt.Invoke(obj, param);
6557
return result;
6658
}
6759

‎APIJSON.NET/APIJSON.NET/Startup.cs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@
1212
using Microsoft.Extensions.Configuration;
1313
using Microsoft.Extensions.DependencyInjection;
1414
using Microsoft.IdentityModel.Tokens;
15+
using SqlKata.Execution;
1516
using Swashbuckle.AspNetCore.Swagger;
17+
using MySql.Data.MySqlClient;
18+
using SqlKata.Compilers;
19+
1620
public class Startup
1721
{
1822
private const string _defaultCorsPolicyName = "localhost";
@@ -26,8 +30,7 @@ public Startup(IConfiguration configuration)
2630
// This method gets called by the runtime. Use this method to add services to the container.
2731
public void ConfigureServices(IServiceCollection services)
2832
{
29-
30-
33+
3134
services.Configure<List<Role>>(Configuration.GetSection("RoleList"));
3235
services.Configure<Dictionary<string,string>>(Configuration.GetSection("tablempper"));
3336
services.Configure<TokenAuthConfiguration>(tokenAuthConfig =>
@@ -40,9 +43,11 @@ public void ConfigureServices(IServiceCollection services)
4043
});
4144
AuthConfigurer.Configure(services, Configuration);
4245

43-
services.AddCors( options => options.AddPolicy( _defaultCorsPolicyName, builder => builder.AllowAnyOrigin()
46+
services.AddCors( options => options.AddPolicy( _defaultCorsPolicyName,
47+
builder =>
48+
builder.AllowAnyOrigin()
4449
.AllowAnyHeader()
45-
.AllowAnyMethod()
50+
.AllowAnyMethod().AllowCredentials()
4651
));
4752
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
4853
services.AddSwaggerGen(c =>
@@ -55,12 +60,15 @@ public void ConfigureServices(IServiceCollection services)
5560
services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
5661
services.AddTransient<IIdentityService, IdentityService>();
5762
services.AddTransient<ITableMapper, TableMapper>();
63+
5864
}
5965

6066
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
6167
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
6268
{
69+
6370
app.UseAuthentication();
71+
6472
app.UseMvc(routes =>
6573
{
6674
routes.MapRoute(

‎APIJSON.NET/APIJSON.NET/appsettings.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"ConnectionStrings": {
33
"DbType": 0, //0:MySql,1:SqlServer,2:Sqlite
44
//"ConnectionString": "Server=liaozengbo\\sql2018; Database=test; User Id=sa;Password=sa123;",
5-
"ConnectionString": "Server=192.168.0.133; Database=test; User Id=root;Password=password;charset=UTF8;"
5+
"ConnectionString": "Server=119.29.9.25;Port=3306;Database=test;Uid=root;Pwd=1q,2w.3e?;CharSet=UTF8;"
66
},
77
"Authentication": {
88
"JwtBearer": {
@@ -41,8 +41,8 @@
4141
}
4242
],
4343
"tablempper": //别名表映射
44-
{
45-
"user": "apijson_user"
46-
}
47-
44+
{
45+
"user": "apijson_user"
46+
}
47+
4848
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /