English 中文(简体)
• 如何在无控制人姓名的情况下手工操作控制器
原标题:How can I instantiate a controller manually based on a url without controller name

I have a CMS that stores the URL of a "page" in the database. The page has a reference to a template, which is just a regular aspx file. Using URL rewriting the request is sent to the correct aspx file.

我们得到多国旅的支持几乎已经完成,但有一个问题。 m形形形形形形形形色色色,它期望着尿中的控制器名(即,我知道,你可以在没有控制器名的情况下为尿液设置一个违约控制器,但所有网页都有不同的控制器),因此难以支持 following状。

www.domain.com/pagename

For example:

www.cnn.com/about-this-site

www.cnn.com/press-release-new-ceo-announced

页面名称与控制器或观点/行动无关,只是一个方便使用的网页名称。

So basically what we would like to do is to take the pagename, find the correct page our system, find the referenced template(controller in mvc) and set up manual routing for that controller and action. Any ideas on how to do that? Or should be just accept that URL s in mvc needs the controller name in most cases?

最佳回答

乳房中的一切都以行道为根据,行车名称为控制器。

这根本不是事实。 是的,这是最荒谬的恶意行为,你可以在盒子外使用。 但这绝不仅限于此,也不局限于地雷危险物质。 您可以(如果是你,你应当)根据以下任何一种情况,确立习惯路线处理逻辑:

  • Custom route constraint - make yourself a custom IRouteConstraint, which you will use on your route handling your content pages served by one particular "content" controller
  • Custom RouteHandler - this is more advanced solution, if you want something really special, but from your question, you do not

If you are planning to have more than one "content-page" handling controller, and you want to choose it from routing data against DB, you have to implement custom ControllerFactory - that is the place where is in MVC stack decided, which controller will be used. There are plenty of examples of this, just google custom controller factory.

问题回答

暂无回答




相关问题
WebForms and ASP.NET MVC co-existence

I am trying to make a WebForms project and ASP.NET MVC per this question. One of the things I ve done to make that happen is that I added a namespaces node to the WebForms web.config: <pages ...

Post back complex object from client side

I m using ASP.NET MVC and Entity Framework. I m going to pass a complex entity to the client side and allow the user to modify it, and post it back to the controller. But I don t know how to do that ...

Create an incremental placeholder in NHaml

What I want to reach is a way to add a script and style placeholder in my master. They will include my initial site.css and jquery.js files. Each haml page or partial can then add their own required ...

asp.net mvc automapper parsing

let s say we have something like this public class Person { public string Name {get; set;} public Country Country {get; set;} } public class PersonViewModel { public Person Person {get; ...

structureMap mocks stub help

I have an BLL that does validation on user input then inserts a parent(PorEO) and then inserts children(PorBoxEO). So there are two calls to the same InsertJCDC. One like this=>InsertJCDC(fakePor)...

ASP.NET MVC: How should it work with subversion?

So, I have an asp.net mvc app that is being worked on by multiple developers in differing capacities. This is our first time working on a mvc app and my first time working with .NET. Our app does not ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

热门标签