asp.net-mvc-controller

ASP.NET MVC Controller Naming Pluralization

笑着哭i 提交于 2019-11-28 17:17:38
问题 RESTful conventions indicate using plural nouns over singular objects. What is the pluralization convention for naming ASP.NET MVC controllers, i.e. ProductController or ProductsController ? 回答1: Some MVC Frameworks use plurals, however the MVC project templates contains a controller called AccountController thus suggesting singlular naming. It doesn't matter. As with most things in the Asp.net MVC framework the choice is yours. There is no real conventions. It's my personal opinion but what

How to achieve a dynamic controller and action method in ASP.NET MVC?

血红的双手。 提交于 2019-11-27 06:59:29
In Asp.net MVC the url structure goes like http://example.com/ {controller}/{action}/{id} For each "controller", say http://example.com/blog , there is a BlogController. But my {controller} portion of the url is not decided pre-hand, but it is dynamically determined at run time, how do I create a "dynamic controller" that maps anything to the same controller which then based on the value and determines what to do? Same thing with {action}, if the {action} portion of my url is also dynamic, is there a way to program this scenario? Ryan Absolutely! You'll need to override the

Getting All Controllers and Actions names in C#

白昼怎懂夜的黑 提交于 2019-11-27 02:47:47
Is it possible to list the names of all controllers and their actions programmatically? I want to implement database driven security for each controller and action. As a developer, I know all controllers and actions and can add them to a database table, but is there any way to add them automatically? You can use reflection to find all Controllers in the current assembly, and then find their public methods that are not decorated with the NonAction attribute. Assembly asm = Assembly.GetExecutingAssembly(); asm.GetTypes() .Where(type=> typeof(Controller).IsAssignableFrom(type)) //filter

Multiple controller types were found that match the URL. This can happen if attribute routes on multiple controllers match the requested URL

萝らか妹 提交于 2019-11-26 18:26:42
问题 ...guess I'm the first to ask about this one? Say you have the following routes, each declared on a different controller: [HttpGet, Route("sign-up/register", Order = 1)] [HttpGet, Route("sign-up/{ticket}", Order = 2)] ... you could do this in MVC 5.0 with the same code except for the Order parameter. But after upgrading to MVC 5.1, you get the exception message in the question title: Multiple controller types were found that match the URL. This can happen if attribute routes on multiple

Getting All Controllers and Actions names in C#

我的未来我决定 提交于 2019-11-26 12:35:59
问题 Is it possible to list the names of all controllers and their actions programmatically? I want to implement database driven security for each controller and action. As a developer, I know all controllers and actions and can add them to a database table, but is there any way to add them automatically? 回答1: You can use reflection to find all Controllers in the current assembly, and then find their public methods that are not decorated with the NonAction attribute. Assembly asm = Assembly