tytd-email-server/Pages/GenerateAppSettings.cshtml.cs

40 lines
1009 B
C#

using System.Text;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Newtonsoft.Json;
using tytdemail.Model;
namespace tytdemail.Pages;
public class GenerateAppSettings : PageModel
{
[BindProperty]
public SMTPConfig Config {get;set;}=new SMTPConfig();
private readonly ILogger<GenerateAppSettings> _logger;
public GenerateAppSettings(ILogger<GenerateAppSettings> logger)
{
_logger = logger;
}
public void OnGet()
{
}
public IActionResult OnPost()
{
Dictionary<string,string> myDict=new Dictionary<string, string>();
myDict.Add("Default","Information");
myDict.Add("Microsoft.AspNetCore","Warning");
object myObj = new{
Logging=new{
LogLevel=myDict,
},
SMTP=Config,
AllowedHosts="*"
};
return File(System.Text.Json.JsonSerializer.SerializeToUtf8Bytes(myObj),"application/json","appsettings.json");
}
}