標籤:mapr 代碼 如何 localhost str lte iis 檔案內容 filters
建立一個mvc項目,在項目中會startup.cs檔案,startup檔案主要是將項目尋找一個宿主
過去,項目一般都是寄宿在iis上的,通過owin可以寄宿到不同的宿主。
可以關閉owin:<appSettings><add key="owin:............"> </>(可以百度)
如何建立視圖,調用方法:
1/建立控制器firstController,在mvcview中會自動產生一個first的檔案夾
2/在控制器中會有一個預設的 ActionrResult index ,滑鼠在此右擊--添加視圖
3/同理:在控制器中直接寫一個方法,然後訪問路徑:localhost/控制器名/方法名
public void responseWrite(){ this.Response.Write("一點半"); this.Response.End(); } public string getStr(){ return "測試";}當執行這兩個方法時,會發現頁面都能出現資訊,其實所有返回的資料都是通過response來輸出到頁面上的
從Global.ascs(全域設定檔)檔案認識mvc
這個Global檔案什麼時候被訪問呢?:網站第一次啟動的時候會率先執行
Global檔案內容:public class MvcApplication : System.Web.HttpApplication { protected void Application_Start() { 1. AreaRegistration.RegisterAllAreas(); 2. FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); 3. RouteConfig.RegisterRoutes(RouteTable.Routes); //路由 4. BundleConfig.RegisterBundles(BundleTable.Bundles); } }
3.這個檔案是mvc的路由註冊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 } ); }
mvc是通過路由來存取碼的
MVC 之 初識(一)