public IActionResult Redirect(int?id) { // if no id is specified if (id == null) { return(Content("no redirect id specified.")); } if (_inMemoryContext.Redirects.Count() == 0) { _seedService.SeedRedirects(); } // get the redirect row by the id var r = _inMemoryContext.Redirects.FirstOrDefault(x => x.RedirectId == id); // if no redirect row is found if (r == null) { return(Content("no matching redirect found.")); } //redirect return(Redirect(r.Url)); }
// To protect from overposting attacks, enable the specific properties you want to bind to, for // more details, see https://aka.ms/RazorPagesCRUD. public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } _context.Attach(RedirectLink).State = EntityState.Modified; try { await _context.SaveChangesAsync(); _seedService.SeedRedirects(); } catch (DbUpdateConcurrencyException) { if (!RedirectExists(RedirectLink.RedirectId)) { return(NotFound()); } else { throw; } } return(RedirectToPage("./Index")); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ISeedService seedService) { seedService.SeedUsers(); seedService.SeedRedirects(); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); app.UseDatabaseErrorPage(); } else { app.UseExceptionHandler("/Error"); // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. app.UseHsts(); } app.UseHttpsRedirection(); app.UseStaticFiles(); app.UseRouting(); app.UseAuthentication(); app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapControllerRoute( name: "redirect", pattern: "r/{id?}", defaults: new { controller = "Home", action = "Redirect" } ); endpoints.MapRazorPages(); }); }
public async Task <IActionResult> OnGetAsync(int?id) { if (id == null) { return(NotFound()); } int seconds = 0; if (!string.IsNullOrEmpty(Request.Query["t"]) && int.TryParse(Request.Query["t"], out seconds)) { RedirectTimeSeconds = seconds; } if (_context.Redirects.Count() == 0) { _seedService.SeedRedirects(); } RedirectLink = await _context.Redirects.FirstOrDefaultAsync(m => m.RedirectId == id); if (RedirectLink == null) { return(NotFound()); } return(Page()); }
// To protect from overposting attacks, enable the specific properties you want to bind to, for // more details, see https://aka.ms/RazorPagesCRUD. public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } _context.Redirects.Add(RedirectLink); await _context.SaveChangesAsync(); _seedService.SeedRedirects(); return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(NotFound()); } RedirectLink = await _context.Redirects.FindAsync(id); if (RedirectLink != null) { _context.Redirects.Remove(RedirectLink); await _context.SaveChangesAsync(); _seedService.SeedRedirects(); } return(RedirectToPage("./Index")); }