【发布时间】:2019-01-10 19:00:29
【问题描述】:
我正在尝试创建一个子站点 (***.com/rentals),并且在导航到它的 uri 时不断收到服务器错误。我在 wwwroot 中创建了文件夹“rentals”作为子文件夹,创建了如下路由:
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
routes.MapRoute(
name: "rentals",
template: "{controller=Rentals}/{action=~/rentals/Index}/{id?}");
});
并使用以下代码生成了一个新控制器:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
// For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
namespace hillandco.Controllers
{
public class RentalsController : Controller
{
// GET: /<controller>/
public IActionResult Index()
{
return View();
}
}
}
我创建了一个 Index.html 文件,不幸的是,使用“https://***.com/rentals”导航到子站点根目录仍然会出错。对我在这里缺少的任何帮助都会很棒!
【问题讨论】:
标签: c# routing asp.net-core-mvc subdirectory