mirror of
https://github.com/yawaflua/yaflay.ru.git
synced 2025-12-13 17:16:26 +02:00
make backend for my site
This commit is contained in:
@@ -1,17 +1,16 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||
using Microsoft.Extensions.Caching.Memory;
|
||||
using yaflay.ru.Models;
|
||||
using yaflay.ru.Models.Tables;
|
||||
using yawaflua.ru.Models;
|
||||
using yawaflua.ru.Models.Tables;
|
||||
|
||||
namespace yaflay.ru.Pages
|
||||
namespace yawaflua.ru.Pages
|
||||
{
|
||||
public class IndexModel : PageModel
|
||||
{
|
||||
private readonly ILogger<IndexModel> _logger;
|
||||
public IMemoryCache cache;
|
||||
public AppDbContext ctx;
|
||||
public string? uri { get; set; } = null;
|
||||
public IndexModel(ILogger<IndexModel> logger, IMemoryCache cache, AppDbContext ctx)
|
||||
{
|
||||
_logger = logger;
|
||||
@@ -19,28 +18,11 @@ namespace yaflay.ru.Pages
|
||||
this.ctx = ctx;
|
||||
}
|
||||
|
||||
public void OnGet(string? uri)
|
||||
public void OnGet()
|
||||
{
|
||||
|
||||
Page();
|
||||
|
||||
this.uri = uri ?? null;
|
||||
Console.WriteLine(uri);
|
||||
if (this.uri != null)
|
||||
{
|
||||
Redirects? fromCache = cache.Get<Redirects>($"redirectsWithUrl-{uri}") ?? null;
|
||||
if (fromCache == null)
|
||||
{
|
||||
fromCache = ctx.Redirects.FirstOrDefault(k => k.uri == uri);
|
||||
Console.WriteLine("Im here!");
|
||||
if (fromCache != null)
|
||||
cache.Set($"redirectsWithUrl-{uri}", (object)fromCache, DateTime.Now.AddMinutes(10));
|
||||
}
|
||||
Console.WriteLine(fromCache?.ToString());
|
||||
Response.Redirect(fromCache?.redirectTo ?? "/404");
|
||||
}
|
||||
else
|
||||
{
|
||||
Page();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user