【问题标题】:Routing for Subsite on ASP.net core 2.1 MVCASP.net core 2.1 MVC 上的子站点路由
【发布时间】: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


    【解决方案1】:

    解决了。路由和控制器操作按原样正常工作;问题是我试图在 wwwroot 中使用子文件夹。当我在“视图”下创建一个文件夹时,我能够很好地使用子站点。

    这种行为看起来很奇怪,但我想从 MVC 的角度和 URI 在 asp.net-core 中的工作方式来看是有道理的。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-07-05
      • 1970-01-01
      • 2020-02-23
      • 2018-08-11
      • 1970-01-01
      相关资源
      最近更新 更多