Load view from bin folder?
In an attempt to have several sites with one central set of views I created an external library with my views. They are marked as content and copy always.
This views library is referenced in my websites and thus with compiling get a "Views" folder in their bin folder.
Then I made a quick custom ViewEngine like this:
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;
}
}
After running I get this screen:
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
What's going wrong?
Also, it feels kinda weird that the bin folder has the views, any other suggestions are welcome.
如果你对这篇文章有疑问,欢迎到本站 社区 发帖提问或使用手Q扫描下方二维码加群参与讨论,获取更多帮助。

评论(2)

If you are absolutely sure the content is in the right folder, then it's probably the server that doesn't let anything to be served from the bin directory, for obvious security reasons.
If that's the case, what I suggest is that you keep the views in the external project, then create HTML extension methods that render those views.
发布评论
需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。