爲了讓多個網站擁有一箇中央視圖集,我創建了一個包含我的視圖的外部庫。它們被標記爲內容並始終複製。
這個視圖庫在我的網站被引用,因此編譯得到他們的bin文件夾中的「Views」文件夾。
後來我做了一個快速自定義視圖引擎是這樣的:從bin文件夾加載視圖?
public class CommonViewLocator: WebFormViewEngine
{
public CommonViewLocator()
{
MasterLocationFormats = new[] {
"~/bin/Views/{1}/{0}.master",
"~/bin/Views/Shared/{0}.master"
};
ViewLocationFormats = new[] {
"~/bin/Views/{1}/{0}.aspx",
"~/bin/Views/{1}/{0}.ascx",
"~/bin/Views/Shared/{0}.aspx",
"~/bin/Views/Shared/{0}.ascx"
};
PartialViewLocationFormats = ViewLocationFormats;
}
}
運行後,我得到這個畫面:
The view 'Index' or its master could not be found. The following locations were searched:
~/Views/Home/Index.aspx
~/Views/Home/Index.ascx
~/Views/Shared/Index.aspx
~/Views/Shared/Index.ascx
~/bin/Views/Home/Index.aspx
~/bin/Views/Home/Index.ascx
~/bin/Views/Shared/Index.aspx
~/bin/Views/Shared/Index.ascx
什麼錯?
此外,感覺有點奇怪,bin文件夾有意見,歡迎任何其他建議。
安全確實是我想到的。但後來我會得到一個安全性錯誤,我猜想。 Htmlhelpers不會讓我擺脫這個,因爲我沒有第一個地方的視圖... – 2009-04-27 15:22:02