diff --git a/Bremen_ESG.csproj b/Bremen_ESG.csproj index f87c494..6541a5b 100644 --- a/Bremen_ESG.csproj +++ b/Bremen_ESG.csproj @@ -10,6 +10,7 @@ + diff --git a/Controllers/ApiController.cs b/Controllers/ApiController.cs index 71d1baa..ca25f1d 100644 --- a/Controllers/ApiController.cs +++ b/Controllers/ApiController.cs @@ -1,52 +1,20 @@ -using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Mvc; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; +using Microsoft.AspNetCore.Mvc; using Newtonsoft.Json; -using Newtonsoft.Json.Linq; using Microsoft.AspNetCore.Cors; using Dapper; -using System.Data; using System.Data.SqlClient; -using System.Web; -using System.Text; using System.Net; -using System.Net.Http; -using System.Net.Http.Headers; using Dapper.Contrib.Extensions; - -using System.IO; -using System.Threading; -using System.Dynamic; -using NPOI; -using NPOI.HPSF; -using NPOI.HSSF; -using NPOI.HSSF.UserModel; -using NPOI.XSSF; -using NPOI.XSSF.UserModel; -using NPOI.POIFS; -using NPOI.Util; -using Microsoft.Extensions.Configuration; -using Org.BouncyCastle.Ocsp; -using System.Security.Policy; -using NPOI.SS.Formula.Functions; using static DbTableClass; -using System.Runtime.InteropServices.ObjectiveC; -using static System.Net.WebRequestMethods; using MimeKit; -using MailKit.Net.Smtp; using MailKit.Security; using System.Net.Mail; using System.Net.Mime; -using NPOI.SS.UserModel; -using NPOI.XWPF.UserModel; -using System.Reflection; namespace Bremen_ESG.Controllers { + [EnableCors("any")] [Route("Api")] public class ApiController : ControllerBase @@ -63,7 +31,8 @@ namespace Bremen_ESG.Controllers this._hostingEnvironment = webHostEnvironment; } - + + [EnableCors("any")] [Route("news_list")] public async Task News_List(IFormCollection obj) { newResult ret = new newResult(); @@ -84,7 +53,7 @@ namespace Bremen_ESG.Controllers } - + [EnableCors("any")] [Route("esg_message")] public async Task Esg_Message(IFormCollection obj) { result ret = new result(); @@ -169,7 +138,7 @@ namespace Bremen_ESG.Controllers return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8"); } - + [EnableCors("any")] [Route("esg_mail")] public async Task Esg_Mail(IFormCollection obj) { result ret = new result(); @@ -204,159 +173,70 @@ namespace Bremen_ESG.Controllers var res = new LinkedResource(fullPath, MediaTypeNames.Image.Jpeg); res.ContentId = Guid.NewGuid().ToString(); - html += ""; - html += ""; - html += ""; - html += ""; - html += " ESG "; - html += " "; - html += " "; - html += " "; - html += " "; - html += " "; - html += " "; - html += " "; - html += " "; - html += " "; - html += " "; - html += " "; - html += ""; - html += ""; - html += ""; - html += "
"; - html += " "; - html += " "; - html += " "; - html += " "; - html += " "; - html += " "; - html += "
"; - html += " "; - html += "
"; - html += " "; - html += " "; - html += " "; - html += " "; - html += " "; - html += " "; - html += "
"; - html += " "; - html += "
"; - html += " "; - html += " "; - html += " "; - html += " "; - html += " "; - html += " "; - html += " "; - html += " "; - html += " "; - html += " "; - html += " "; - html += " "; - html += "
"; - html += "
您好,謝謝您填寫ESG快速檢測
詳細的測驗結果分析,請點擊以下連結查看:
"; - html += "
"; - html += " "; - html += " "; - html += " "; - html += " "; - html += "
"; - html += " 查看結果 "; - html += "
"; - html += "
"; - html += " "; - html += " "; - html += " "; - html += " "; - html += " "; - html += " "; - html += "
"; - html += " "; - html += " "; - html += " "; - html += "
"; - html += "
"; - html += "
"; - html += " "; - html += "
"; - html += "
"; - html += " "; - html += "
"; - html += "
"; + html += ""; + html += ""; + html += " "; + html += " "; + html += " "; + html += " "; + html += " "; + html += "
"; + html += " "; + html += "
"; + html += " "; + html += " "; + html += " "; + html += " "; + html += " "; + html += " "; + html += "
"; + html += " "; + html += "
"; + html += " "; + html += " "; + html += " "; + html += " "; + html += " "; + html += " "; + html += " "; + html += " "; + html += " "; + html += " "; + html += " "; + html += " "; + html += "
"; + html += "
您好,謝謝您填寫ESG快速檢測
詳細的測驗結果分析,請點擊以下連結查看:
"; + html += "
"; + html += " "; + html += " "; + html += " "; + html += " "; + html += "
"; + html += " 查看結果 "; + html += "
"; + html += "
"; + html += " "; + html += " "; + html += " "; + html += " "; + html += " "; + html += " "; + html += "
"; + html += " "; + html += " "; + html += " "; + html += "
"; + html += "
"; + html += "
"; + html += " "; + html += "
"; + html += "
"; + html += " "; + html += "
"; html += ""; - html += ""; - html += ""; //建立AlternativeView - var altView = AlternateView.CreateAlternateViewFromString(html, null, MediaTypeNames.Text.Html); + var altView = AlternateView.CreateAlternateViewFromString(html, null, "text/html"); //將圖檔資源加入AlternativeView altView.LinkedResources.Add(res); @@ -401,7 +281,7 @@ namespace Bremen_ESG.Controllers mail.AlternateViews.Add(altView); mail.To.Add(toEmail); - mail.Bcc.Add("dk96pccu@gmail.com"); + mail.Bcc.Add("dk96pccu@gmail.com,sunny.lin@bremen.com.tw"); mail.From = new MailAddress(GlobalClass.appsettings("MailServer:smtp_username"), "ESG快速檢測結果分析", System.Text.Encoding.UTF8); mail.Subject = "ESG快速檢測結果分析"; await client.SendMailAsync(mail).ContinueWith(task => diff --git a/Program.cs b/Program.cs index 9aef6c0..4b6e8e8 100644 --- a/Program.cs +++ b/Program.cs @@ -49,22 +49,33 @@ var builder = WebApplication.CreateBuilder(args); // }); //}); +// Add services to the container. builder.Services.AddCors(options => { - options.AddPolicy("AllowAll", builder => - builder.AllowAnyOrigin() - .AllowAnyMethod() - .AllowAnyHeader()); + options.AddPolicy(name: "any", builder => + { + builder.WithOrigins("https://www.bremen.com.tw", + "https://bremen.com.tw") + .AllowAnyHeader() + .AllowAnyMethod(); + }); }); + + + + // Add services to the container. builder.Services.AddControllersWithViews(); //builder.Services.AddControllers(); builder.Services.TryAddSingleton(); + var app = builder.Build(); + + // Configure the HTTP request pipeline. if (!app.Environment.IsDevelopment()) { @@ -80,13 +91,17 @@ defaultFilesOptions.DefaultFileNames.Add("iisstart.htm"); app.UseDefaultFiles(defaultFilesOptions); app.UseHttpsRedirection(); + + + app.UseStaticFiles(); + app.UseRouting(); -//app.UseCors("AllowAnyOrigins"); -//app.UseCors("AllowAll"); -//app.UseCors(); -app.UseAuthorization(); + +app.UseCors("any"); + +//app.UseAuthorization(); app.MapControllerRoute( name: "default",