Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what is the entry point for an asp.net mvc 4 application?

Tags:

asp.net-mvc

I am learning my way around an MVC 4 application but am new to the mvc platform. If I were learning a new java application, I would start reading code from the main method and go from there. What is the analog for an asp.net mvc application?

I launch the application from the following URL: http://server/directory/home?iv-user=tuser

like image 550
bernie2436 Avatar asked Jun 04 '13 16:06

bernie2436


People also ask

What is the entry point of ASP.NET application?

The Main() method is the entry point in a . NET or a . NET Core application. Because Main() is the entry point of your application, you can have one and only one Main() method in your project.

What's the entry point of an application in the MVC app architecture?

The view is the entry point to the Application. One to many relationships between Controller & View.

What is ASP.NET MVC 4 web application?

In this article. ASP.NET MVC 4 is a framework for building scalable, standards-based web applications using well-established design patterns and the power of the ASP.NET and the . NET framework. This new, fourth version of the framework focuses on making mobile web application development easier.


3 Answers

The Global.asax.cs file, where there is the start method Application_Start might be what you are looking for. That is the code which is run when the app starts.

protected void Application_Start()
{
    ...
    RouteConfig.RegisterRoutes(RouteTable.Routes);
    ...
}

But looking at the url you have posted it might be the HomeController or DirectoryController file. Unfortunately, I cannot tell that from looking at your route.

A sample route register code is as below where we can see that

  1. The URL /{controller}/{action}/{id}

  2. The default for controller/action/id is Home/Index/optional

So if you run your web with the starting url as http://localhost:52763/, it is indeed will call http://localhost:52763/Home/Index

public static void RegisterRoutes(RouteCollection routes)
{
    routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
    routes.MapRoute(
        name: "Default",
        url: "{controller}/{action}/{id}",
        defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
    );
}
like image 172
MaxWillmott Avatar answered Dec 23 '22 07:12

MaxWillmott


It's HTTP. You make a request to the web server for a resource, as you have specified above, and the controller responds.

So in ASP.NET MVC, you have multiple entry points: each action method.

MSDN Controllers and Action Methods in ASP.NET MVC

like image 32
p.campbell Avatar answered Dec 23 '22 06:12

p.campbell


There is an application_start() method in global.asax.cs. As for the controller's concern for the request, its starts in the constructor of the controller then the method for the requested action.

like image 41
Gabe Avatar answered Dec 23 '22 06:12

Gabe