C#的MVC尋找對應的控制器首先是尋找當前域的
如果找不到就會尋找備用的..
但是有些時候我們是不想他去尋找備用的控制器.
這裡就涉及到了一個DataToken
複製代碼 代碼如下:routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional }, // Parameter defaults
new string[] { "Reader.Controllers" }
);
我第一次是使用new string來區分,可惜他還是會去尋找.我翻閱了一些資料之後
發現如果要取消備用控制器需要這麼寫
複製代碼 代碼如下:routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional }, // Parameter defaults
new string[] { "Reader.Controllers" }
).DataTokens["UseNamespaceFallBack"]=false;
這樣我們就取消的使用備用控制器的操作了.
另外備份一下MVC的一些公約複製代碼 代碼如下:protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
//db.ContextOptions.LazyLoadingEnabled = false;
//db.ContextOptions.ProxyCreationEnabled = false;
modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();//移除複數表名的契約
modelBuilder.Conventions.Remove<IncludeMetadataConvention>();
base.OnModelCreating(modelBuilder);
/*
可以刪除的公約有:
Namespace:System.Data.Entity.ModelConfiguration.Conventions.Edm
• AssociationInverseDiscoveryConvention
尋找導航上互相引用的類的屬性,並將它們配置為逆屬性的相同的關係。
• ComplexTypeDiscoveryConvention
尋找有沒有主鍵的類型,並將它們配置為複雜類型。
• DeclaredPropertyOrderingConvention
確保每個實體的主要關鍵屬性優先於其他屬性。
• ForeignKeyAssociationMultiplicityConvention
配置是必需的還是可選的關係基於為空白性外鍵屬性,如果包含在類定義中。
• IdKeyDiscoveryConvention
尋找名為 Id 或 <TypeName> Id 的屬性,並將他們配置作為主鍵。
• NavigationPropertyNameForeignKeyDiscoveryConvention
使用外鍵關係,使用 <NavigationProperty> <PrimaryKeyProperty> 模式作為屬性的外觀。
• OneToManyCascadeDeleteConvention
交換器上層疊刪除,所需的關係。
• OneToOneConstraintIntroductionConvention
將配置為一個: 一個關係的外鍵的主鍵。
• PluralizingEntitySetNameConvention
配置為多元化的類型名稱的實體資料模型中的實體集的名稱。
• PrimaryKeyNameForeignKeyDiscoveryConvention
使用外鍵關係,使用 <PrimaryKeyProperty> 模式作為屬性的外觀。
• PropertyMaxLengthConvention
配置所有的字串和位元組 [] 屬性,預設情況下具有最大長度。
• StoreGeneratedIdentityKeyConvention
配置預設情況下將標識所有整數的主鍵。
• TypeNameForeignKeyDiscoveryConvention
使用外鍵關係,使用 <PrincipalTypeName> <PrimaryKeyProperty> 模式作為屬性的外觀。
*/}