我正在尝试在ASP.NET MVC 4中设置自定义路由。我希望通过
访问我的路由http://www.mydomain.com/high-school/student/1
在尝试设置此路由时,我在RouteConfig.cs中添加了以下内容
routes.MapRoute(
name: "HSStudentProfile",
url: "high-school/student",
defaults: new { controller = "Students", action = "HSStudentProfile" }
);
StudentsController.cs
public class StudentsController : Controller
{
public ActionResult HSStudentProfile()
{
return View("~/Views/Shared/Course/Index.cshtml");
}
}
如果我访问上面提到的网址,我会收到403.14错误。如果我更新路由配置以使用
routes.MapRoute(
name: "HSStudentProfile",
url: "{controller}/high-school/student",
defaults: new { controller = "Students", action = "HSStudentProfile" }
);
但是,我必须将URL路径更改为
http://www.mydomain.com/Students/high-school/student/1
有没有办法在我的RouteConfig中没有{controller}的情况下执行此操作?