asp.net mvc 4應用程序的切入點是什么?

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


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?

我正在學習MVC 4應用程序,但我是mvc平台的新手。如果我正在學習一個新的java應用程序,我將開始從main方法中讀取代碼並從那里開始。 asp.net mvc應用程序的模擬是什么?

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

我從以下URL啟動應用程序:http:// server / directory / home?iv-user = tuser

6 个解决方案

#1


2  

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

這是HTTP。如上所述,您向Web服務器請求資源,並且控制器響應。

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

因此,在ASP.NET MVC中,您有多個入口點:每個操作方法。

MSDN Controllers and Action Methods in ASP.NET MVC

ASP.NET MVC中的MSDN控制器和操作方法

#2


26  

The Global.asax.cx 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.

Global.asax.cx文件,其中有啟動方法Application_Start,可能就是您要查找的內容。這是應用程序啟動時運行的代碼。

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 from looking at your route.

但是看看你發布的url可能是HomeController或DirectoryController文件。不幸的是,我看不出你的路線。

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

一個示例路由寄存器代碼如下所示我們可以看到

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

    網址/ {controller} / {action} / {id}

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

    controller / action / id的默認值為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

因此,如果您使用起始URL作為http:// localhost:52763 /運行您的網站,它確實會調用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 }
    );
}

#3


1  

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.

global.asax.cs中有一個application_start()方法。至於控制器對請求的關注,它從控制器的構造函數開始,然后是請求的操作的方法。

#4


0  

In the case you have given, if you want to find the first bit of non-framework code which is executed, you would look for HomeController.cs in the Controllers directory and look for the Index or Default method which will accept a parameter of iv-user.

在你給出的情況下,如果你想找到執行的第一個非框架代碼,你可以在Controllers目錄中查找HomeController.cs並查找將接受iv參數的Index或Default方法-用戶。

To see the full page lifecycle, look here: http://www.red-gate.com/products/dotnet-development/ants-performance-profiler/entrypage/be-ahead-of-the-game-poster2. This takes you from the incoming HTTP request to the final rendered view.

要查看整個頁面生命周期,請查看此處:http://www.red-gate.com/products/dotnet-development/ants-performance-profiler/entrypage/be-ahead-of-the-game-poster2。這會將您從傳入的HTTP請求轉到最終的渲染視圖。

#5


0  

MR P.Campbell was right. For more detail please review as: http://msdn.microsoft.com/en-us/library/dd381612(v=vs.98).aspx

MR P.Campbell先生是對的。有關更多詳細信息,請查看:http://msdn.microsoft.com/en-us/library/dd381612(v = vs.98).aspx

I copied it's main content:

我復制了它的主要內容:

Understanding MVC Application Execution

了解MVC應用程序執行

Requests to an ASP.NET MVC-based Web application first pass through the UrlRoutingModule object, which is an HTTP module. This module parses the request and performs route selection. The UrlRoutingModule object selects the first route object that matches the current request. (A route object is a class that implements RouteBase, and is typically an instance of the Route class.) If no routes match, the UrlRoutingModule object does nothing and lets the request fall back to the regular ASP.NET or IIS request processing. From the selected Route object, the UrlRoutingModule object obtains an object that implements the IRouteHandler interface and that is associated with the Route object. Typically, in an MVC application, this will be an instance of the MvcRouteHandler class. The MvcRouteHandler instance creates an MvcHandler object that implements the IHttpHandler interface. The MvcHandler object then selects the controller that will ultimately handle the request. For more information, see ASP.NET Routing.

對基於ASP.NET MVC的Web應用程序的請求首先通過UrlRoutingModule對象,該對象是一個HTTP模塊。該模塊解析請求並執行路由選擇。 UrlRoutingModule對象選擇與當前請求匹配的第一個路由對象。 (路由對象是實現RouteBase的類,通常是Route類的實例。)如果沒有路由匹配,則UrlRoutingModule對象不執行任何操作,並使請求回退到常規ASP.NET或IIS請求處理。從選定的Route對象中,UrlRoutingModule對象獲取一個實現IRouteHandler接口並與Route對象關聯的對象。通常,在MVC應用程序中,這將是MvcRouteHandler類的實例。 MvcRouteHandler實例創建一個實現IHttpHandler接口的MvcHandler對象。然后,MvcHandler對象選擇最終將處理請求的控制器。有關更多信息,請參閱ASP.NET路由。

#6


0  

Here this link gives very detailed explanation of overall execution flow in MVC along with it's life-cycle events. A-Detailed-Walkthrough-of-ASP-NET-MVC-Request-Life.

這個鏈接給出了MVC中整體執行流程及其生命周期事件的非常詳細的說明。 A-詳細-演練-的-ASP-NET-MVC請求生命。

For deeper details follow this link. Asp-Net-mvc-life-cycle

有關詳細信息,請點擊此鏈接。 ASP-NET-MVC-生命周期


注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:https://www.itdaan.com/blog/2013/06/04/9637a0fb2449a141832ccf91472b7da2.html



 
粤ICP备14056181号  © 2014-2021 ITdaan.com