开发 url-shorter 用于自我教育,但未能实现基本功能 - 2 个工作视图。
尝试了不同的动作重载Redir(),Redir(string hash)。还有这么多不同的路由版本
我在控制器中得到了该操作
[HttpGet]
public IActionResult Index()
{
return View(null);
}
[HttpPost]
public IActionResult Index(string url,[FromServices] IComputeHash computeService)
{ ...
return View("Index", url_builder);//url_builder is link like "localhost:44397/Home/Redir?hash=D9F57F9E10FB7CB61F178582A9DD6C1A"
}
public IActionResult Redir() // I also tried version with parameter Redir(string hash)
{
string hash = Request.Query.FirstOrDefault(p => p.Key == "hash").Value;
DbField field = db.UrlHashes.Find(hash);// db {key=hash, value=link}
if (field != null)
{ return View("Redir"); }//View is used for testing is action working at all or not
//{ return Redirect(field.link); }//actually it just need to redirect to a link
else
{ return RedirectToAction("Error"); }
}
public IActionResult Error()
{ ... }
目前我使用这种路由设置,并尝试了我想到的一切
app.UseMvc(routes =>
{
routes.MapRoute(
name: "redir",
template: "{controller=Home}/{Redir}/{hash}");
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/");
});
当我要访问localhost:44397/Home/Redir?hash=D9F57F9E10FB7CB61F178582A9DD6C1A类型链接时,我刚刚遇到浏览器错误,没有加载视图,没有重定向到错误页面,甚至没有因某些错误而崩溃。只是普通浏览器 - 我无法加载这个东西。
30秒到达战场
红糖糍粑
相关分类