views:

115

answers:

2

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.

A: 

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.

çağdaş
Security was indeed what I was thinking about. But then I would get a security error I would guess.Htmlhelpers will not get me out of this since I don't have a view in the first place...
borisCallens
Whay I meant by Htmlhelpers suggestion was that, don't put the views in the bin folder at all, but have them rendered and returned from the external library, if that's possible.
çağdaş
A: 

Why not use a post-build action on the projects to move the files in /bin/Views into /Views? Then you wouldn't have to do anything special in code.

Jeremy