Успадкоўванне кантролера ASP.NET MVC 4 (ASP.NET MVC 4 controller inheritance)


問題描述

Успадкоўванне кантролера ASP.NET MVC 4 (ASP.NET MVC 4 controller inheritance)

I have the following setup: BaseController1 inherits System.Web.Mvc.Controller. This controller is compiled into a separate dll that is referenced from my project. BaseController2 inherits BaseController1 in my project. MyController inherits BaseController2. When I run application with this setup, I get 404 error. But if BaseController2 inherits directly System.Web.Mvc.Controller, and I run application with this setup, everything works as expected. I have default constructor for all inherited controllers with : base() called. The BaseController1 within assembly is compiled using references to asp.net mvc 3, and my project relies completely on asp.net mvc 4. Can this be the problem? Or I am doing something wrong. Thanks in advance!

‑‑‑‑‑

參考解法

方法 1:

You're doing nothing wrong, but you will have to make MVC look in the specific assembly/namespace:

ControllerBuilder.Current.DefaultNamespaces.Add(
    "ExternalAssembly.Controllers");

This has already been answered in this question: asp.net mvc put controllers into a separate project

(by MaxReacPbirkoff)

參考文件

  1. ASP.NET MVC 4 controller inheritance (CC BY‑SA 3.0/4.0)

#http-status-code-404 #ASP.NET #controller #inheritance






相關問題

PHP在simplexml print_r上返回頁面錯誤 (PHP returning page error on simplexml print_r)

Apache Camel 和 CXF:多個 cxf:rsServer 標籤 .. 這可能嗎? (Apache Camel and CXF: Mutlitple cxf:rsServer tags .. is this possible?)

Penyiapan situs MSM 5 dengan pengalihan halaman 404 umum (MSM 5 site setup with a common 404 page redirect)

Успадкоўванне кантролера ASP.NET MVC 4 (ASP.NET MVC 4 controller inheritance)

Laravel Put Route Giving 404 錯誤 (Laravel Put Route Giving 404 Error)

WordPress 404 頁 (Wordpress 404 PAGE)

Gửi email tự động khi tải trang (Send Email Automatically On Page Load)

何時顯示“未找到記錄”頁面或返回 HTTP 404? (When to display "Record Not Found" Page or return HTTP 404?)

Breeze.js:處理空結果 (Breeze.js: Handling empty results)

如何從php中製作的404自定義頁面獲取用戶嘗試訪問的鏈接 (How to get the link that the user tried to visit, from a 404 custom page made in php)

Flask 文件上傳失敗並出現 404 錯誤 (Flask File Upload fails with 404 error)

如何在 ASP.NET 頁面中對超鏈接和內容進行變基? (How do you rebase hyperlinks and content in an ASP.NET page?)







留言討論