1
0
Fork 0
mirror of https://github.com/miawinter98/just-short-it.git synced 2024-09-20 01:39:00 +00:00
just-short-it/Pages/Index.cshtml.cs

33 lines
920 B
C#
Raw Normal View History

2023-04-15 13:40:46 +00:00
using System.Text;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.Extensions.Caching.Distributed;
namespace JustShortIt.Pages;
public class IndexModel : PageModel {
private ILogger<IndexModel> Logger { get; }
private IDistributedCache Db { get; set; }
// Bound property
public string? Id { get; set; }
public string? ErrorMessage { get; set; }
public IndexModel(ILogger<IndexModel> logger, IDistributedCache distributedCache) {
Logger = logger;
Db = distributedCache;
}
public async Task<IActionResult> OnGetAsync(string? id) {
Id = id;
if (Id is not null) {
string? data = await Db.GetStringAsync(Id);
if (data is not null) return Redirect(data);
ErrorMessage = "Redirect ID not found, it may have been deleted or expired";
}
return Page();
}
}