GeezerVison is showing github.com — #跨域问题# · JerryMouseLi/APIJSON.NET@486a035
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: APIJSON.NET/APIJSON.NET/APIJSON.NET.csproj +8-2Lines changed: 8 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | | -<Project Sdk="Microsoft.NET.Sdk.Web"> | | 1 | +<Project Sdk="Microsoft.NET.Sdk.Web"> | 2 | 2 |
| 3 | 3 | <PropertyGroup> | 4 | 4 | <TargetFramework>netcoreapp2.1</TargetFramework> | | 16 | 16 |
| 17 | 17 | <ItemGroup> | 18 | 18 | <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" /> | 20 | 20 | <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" /> | 21 | 24 | <PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.1.0" /> | 22 | 25 | <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" /> | 23 | 29 | <PackageReference Include="sqlSugarCore" Version="4.6.4.9" /> | 24 | 30 | <PackageReference Include="Swashbuckle.AspNetCore" Version="3.0.0" /> | 25 | 31 | <PackageReference Include="Swashbuckle.AspNetCore.Annotations" Version="3.0.0" /> | |
Collapse file Copy file name to clipboardExpand all lines: APIJSON.NET/APIJSON.NET/Controllers/JsonController.cs +2Lines changed: 2 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 11 | 11 | using System.Linq; | 12 | 12 | using APIJSON.NET.Services; | 13 | 13 | using System.Reflection; | | 14 | + using Microsoft.AspNetCore.Cors; | 14 | 15 |
| 15 | 16 | [Route("api/[controller]")] | 16 | 17 | [ApiController] | | 18 | + [EnableCors("localhost")] | 17 | 19 | public class JsonController : ControllerBase | 18 | 20 | { | 19 | 21 |
| |
Collapse file Copy file name to clipboardExpand all lines: APIJSON.NET/APIJSON.NET/Controllers/TokenController.cs +4-2Lines changed: 4 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 7 | 7 | using System.Text; | 8 | 8 | using System.Threading.Tasks; | 9 | 9 | using Microsoft.AspNetCore.Authorization; | | 10 | +using Microsoft.AspNetCore.Cors; | 10 | 11 | using Microsoft.AspNetCore.Http; | 11 | 12 | using Microsoft.AspNetCore.Mvc; | 12 | 13 | using Microsoft.Extensions.Options; | @@ -17,6 +18,7 @@ namespace APIJSON.NET.Controllers | 17 | 18 | [Route("api/[controller]/[action]")] | 18 | 19 | [ApiController] | 19 | 20 | [Authorize] | | 21 | + [EnableCors("localhost")] | 20 | 22 | public class TokenController : ControllerBase | 21 | 23 | { | 22 | 24 | private DbContext db; | @@ -28,7 +30,7 @@ public TokenController(DbContext _db, IOptions<TokenAuthConfiguration> configura | 28 | 30 | } | 29 | 31 | [HttpPost("/token")] | 30 | 32 | [AllowAnonymous] | 31 | | - public IActionResult Create([FromBody]TokenInput input) | | 33 | + public ActionResult Create([FromBody]TokenInput input) | 32 | 34 | { | 33 | 35 | JObject ht = new JObject(); | 34 | 36 | ht.Add("code", "200"); | @@ -72,7 +74,7 @@ public IActionResult Create([FromBody]TokenInput input) | 72 | 74 | return Ok(ht); | 73 | 75 | } | 74 | 76 | [HttpGet] | 75 | | - public IActionResult GetRole() | | 77 | + public ActionResult GetRole() | 76 | 78 | { | 77 | 79 | return Ok(User.FindFirstValue(ClaimTypes.Role)); | 78 | 80 | } | |
Collapse file Copy file name to clipboard +2-1Lines changed: 2 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
| 1 | | -FROM microsoft/aspnetcore:latest | | 1 | +FROM microsoft/dotnet:2.1.2-aspnetcore-runtime | 2 | 2 |
| 3 | 3 | WORKDIR /app | 4 | 4 | COPY . . | 5 | 5 |
| | 6 | + | 6 | 7 | ENTRYPOINT ["dotnet", "APIJSON.NET.dll"] |
Collapse file Copy file name to clipboard +6-11Lines changed: 6 additions & 11 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 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; | 7 | 2 | using Microsoft.AspNetCore.Hosting; | 8 | | -using Microsoft.Extensions.Configuration; | 9 | | -using Microsoft.Extensions.Logging; | | 3 | +using System.Net; | 10 | 4 |
| 11 | 5 | namespace APIJSON.NET | 12 | 6 | { | @@ -17,8 +11,9 @@ public static void Main(string[] args) | 17 | 11 | CreateWebHostBuilder(args).Build().Run(); | 18 | 12 | } | 19 | 13 |
| 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 | + } | 23 | 18 | } | 24 | 19 | } |
Collapse file Copy file name to clipboardExpand all lines: APIJSON.NET/APIJSON.NET/SelectTable.cs -8Lines changed: 0 additions & 8 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -54,14 +54,6 @@ public object ExecFunc(string funcname,object[] param, Type[] types) | 54 | 54 |
| 55 | 55 | var reflector = method.GetReflector(); | 56 | 56 | 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); | 65 | 57 | return result; | 66 | 58 | } | 67 | 59 |
| |
Collapse file Copy file name to clipboardExpand all lines: APIJSON.NET/APIJSON.NET/Startup.cs +12-4Lines changed: 12 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 12 | 12 | using Microsoft.Extensions.Configuration; | 13 | 13 | using Microsoft.Extensions.DependencyInjection; | 14 | 14 | using Microsoft.IdentityModel.Tokens; | | 15 | + using SqlKata.Execution; | 15 | 16 | using Swashbuckle.AspNetCore.Swagger; | | 17 | + using MySql.Data.MySqlClient; | | 18 | + using SqlKata.Compilers; | | 19 | + | 16 | 20 | public class Startup | 17 | 21 | { | 18 | 22 | private const string _defaultCorsPolicyName = "localhost"; | @@ -26,8 +30,7 @@ public Startup(IConfiguration configuration) | 26 | 30 | // This method gets called by the runtime. Use this method to add services to the container. | 27 | 31 | public void ConfigureServices(IServiceCollection services) | 28 | 32 | { | 29 | | - | 30 | | - | | 33 | + | 31 | 34 | services.Configure<List<Role>>(Configuration.GetSection("RoleList")); | 32 | 35 | services.Configure<Dictionary<string,string>>(Configuration.GetSection("tablempper")); | 33 | 36 | services.Configure<TokenAuthConfiguration>(tokenAuthConfig => | @@ -40,9 +43,11 @@ public void ConfigureServices(IServiceCollection services) | 40 | 43 | }); | 41 | 44 | AuthConfigurer.Configure(services, Configuration); | 42 | 45 |
| 43 | | - services.AddCors( options => options.AddPolicy( _defaultCorsPolicyName, builder => builder.AllowAnyOrigin() | | 46 | + services.AddCors( options => options.AddPolicy( _defaultCorsPolicyName, | | 47 | + builder => | | 48 | + builder.AllowAnyOrigin() | 44 | 49 | .AllowAnyHeader() | 45 | | - .AllowAnyMethod() | | 50 | + .AllowAnyMethod().AllowCredentials() | 46 | 51 | )); | 47 | 52 | services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1); | 48 | 53 | services.AddSwaggerGen(c => | @@ -55,12 +60,15 @@ public void ConfigureServices(IServiceCollection services) | 55 | 60 | services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>(); | 56 | 61 | services.AddTransient<IIdentityService, IdentityService>(); | 57 | 62 | services.AddTransient<ITableMapper, TableMapper>(); | | 63 | + | 58 | 64 | } | 59 | 65 |
| 60 | 66 | // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. | 61 | 67 | public void Configure(IApplicationBuilder app, IHostingEnvironment env) | 62 | 68 | { | | 69 | + | 63 | 70 | app.UseAuthentication(); | | 71 | + | 64 | 72 | app.UseMvc(routes => | 65 | 73 | { | 66 | 74 | routes.MapRoute( | |
Collapse file Copy file name to clipboardExpand all lines: APIJSON.NET/APIJSON.NET/appsettings.json +5-5Lines changed: 5 additions & 5 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 2 | 2 | "ConnectionStrings": { | 3 | 3 | "DbType": 0, //0:MySql,1:SqlServer,2:Sqlite | 4 | 4 | //"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;" | 6 | 6 | }, | 7 | 7 | "Authentication": { | 8 | 8 | "JwtBearer": { | | 41 | 41 | } | 42 | 42 | ], | 43 | 43 | "tablempper": //别名表映射 | 44 | | - { | 45 | | - "user": "apijson_user" | 46 | | - } | 47 | | - | | 44 | + { | | 45 | + "user": "apijson_user" | | 46 | + } | | 47 | + | 48 | 48 | } |
|