是否可以使用ASP.NET MVC路由使用子域信息来确定其路由?例如:
或者,我可以这样做,所以这两个都与username参数进入相同的控制器/动作?
我正在尝试建立自己的小cms.我创建了一个抽象的pageBase类,它由Static,Reviews,Articles,News继承.每个都有自己的控制器方法.
我的问题是我需要允许管理员定义自己的自定义路径级别.例如news\local\mynewdog或Articles\events\conventions\mycon.所以我想要一种传递字符串数组并设置自定义路由的方法.
c# asp.net-mvc url-routing asp.net-mvc-routing custom-routes
我正在研究混合路由 Angular 2 和 ASP.NET Core 2(razor)项目。您将如何跳出角度路由并获得剃刀页面?我尝试使用 angular 路由捕获所有未知路由并重新加载未知路由,但是如果有路由 ASP.NET 并且 angular 无法识别它进入循环。类的Configure方法Startup包含这个。
public void Configure(IApplicationBuilder app)
{
app.UseMvc(routes =>
{
routes.MapRoute(
name: "Index",
defaults: new { controller = "controller", action = "Index" },
template: "{controller}");
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
routes.MapRoute(
name: "Login",
defaults: new { controller = "Sessions", action = "New" },
template: "Login");
});
app.UseSpa(spa =>
{
// To learn more about options for serving an Angular SPA from ASP.NET Core,
// see …Run Code Online (Sandbox Code Playgroud) 这是场景的方式:
TestController的Index方法TestControllerIndexAction方法TestController:
[Authorize]
public class TestController : Controller
{
// GET: Test
public ViewResult Index()
{
return View();
}
[ValidateInput(false)]
public ActionResult ActionTest()
{
return new EmptyResult();
}
}
Run Code Online (Sandbox Code Playgroud)
HomeController:
[Authorize]
public class HomeController : Controller
{
public ActionResult Index()
{
return View();
}
}
Run Code Online (Sandbox Code Playgroud)
AccountController:
public class AccountController : Controller
{
[AllowAnonymous]
public ActionResult Login()
{
return View(); …Run Code Online (Sandbox Code Playgroud) security authentication asp.net-mvc forms-authentication asp.net-mvc-routing
在 MVC5 路由中,我需要一种情况。我有 2 个具有相同控制器名称的命名空间。我想在没有冲突的情况下在控制器之间动态选择
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}",
new { controller = "Home", action = "Index", id = UrlParameter.Optional },
new[] { "Namespace1","Namespace2" });
Run Code Online (Sandbox Code Playgroud)
在这里,如果在两个命名空间下有 2 个具有相同名称和操作的控制器,则会出现冲突错误。我想做的是优先考虑命名空间。
如果两个命名空间都有 Home.Index 操作,我希望 Namespace1 带头而不是错误。如果namespace1 没有我希望系统检查Namespace2 的操作。
我尝试了几种方法,但我不想使用属性路由更好的架构。
我们有一个 BaseECommerce asp.net mvc 项目和继承 BaseEcommerce 项目的 UI 项目。目的是如果 UI 项目中有相同的 Controller 和 Action 使用它。否则使用基础项目。
感谢帮助。
cI经历了有关区域路由的各种帖子,但我仍然无法解决我的问题.
我想以有两条路线的方式拆分我的应用程序.
/Areas/Panel /Areas/Website在每个区域内都有HomeController与行动相对应的适当方法.
每当用户登陆任何1级路线时,我都希望如此:
是针对 /Areas/Website/{controller}/{action}
或者替代
至 /Areas/Panel/{controller}/{action}
我目前的MVC路线是:
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
routes.MapRoute(
name: "area",
template: "{area:exists}/{controller=Home}/{action=Index}/{id?}");
});
Run Code Online (Sandbox Code Playgroud)
但它不起作用,可能是因为我不完全理解如何告诉路由器将Website区域用作默认值.我在控制器本身之前尝试了各种指令,但它没有用.
我可以问你的意见吗?
先感谢您.
我在RouteConfig中有3条路由:
routes.MapRoute(
name: "ByGroupName",
url: "catalog/{categoryname}/{groupname}",
defaults: new { controller = "Catalog", action = "Catalog" }
);
routes.MapRoute(
name: "ByCatName",
url: "catalog/{categoryname}",
defaults: new { controller = "Catalog", action = "Catalog" }
);
routes.MapRoute(
name: "ByBrandId",
url: "catalog/brand/{brandId}",
defaults: new { controller = "Catalog", action = "Catalog" }
);
Run Code Online (Sandbox Code Playgroud)
这是我的动作控制器接收参数:
public ActionResult Catalog(
string categoryName = null,
string groupName = null,
int pageNumber = 1,
int orderBy = 5,
int pageSize = 20,
int brandId = 0,
bool bundle = …Run Code Online (Sandbox Code Playgroud) asp.net asp.net-mvc asp.net-mvc-routing maproute asp.net-mvc-5
我有这条路线:
routes.MapRoute(
"PlaceDetails",
"{controller}/{action}/{id}",
new { controller = "Place", action = "Details", id = UrlParameter.Optional }
);
Run Code Online (Sandbox Code Playgroud)
这路由很好:mysite.com/place/details/123
使Id 123可用于场所控制器的详细操作 - 然后可以查找位置'123'.
但是 - 此URL也会传递给控制器:mysite.com/place/details/
我希望它返回HttpNotFound- 但它向控制器发送一个空的Id - 并要求我处理它.
如果路由本身实现了这一点,而不是在控制器本身中需要不合理的空检查,那似乎更整洁.
我在谷歌没有发现这个具体问题.
我怎样才能做到这一点?
asp.net-mvc ×7
c# ×5
asp.net ×2
asp.net-core ×2
.net-core ×1
angular ×1
maproute ×1
routing ×1
security ×1
url-routing ×1