سؤال

I'm using Nancy 0.14.1.0 with a Razor view. Things are going fine as long as I work with the internal webserver in VS 2010. Now I did deploy the stuff to my webserver running IIS 6. The route is

       Get["/api/v1/admin/clients"] = parameters => {
            return View["Admin/view", new DataAccessLayer(Context).admin_get_clients()];
        };

which returns a List of clients (doesn't matter here).

The directory structure on the server is

bin
Content
Shared
   |--- _Layout.cshtml
Views
   |--- Admin
         |--- view.cshtml

The exception I catch is

Nancy.ViewEngines.ViewNotFoundException: Unable to locate view 'Admin/view' Currently available view engine extensions: sshtml,html,htm Locations inspected: ,,,,views/api/Admin/view,api/Admin/view,views/Admin/view,Admin/view Root path: C:\Inetpub\Websites\Test\api\ 

What concerns me a bit is the "available view engine extensions" entry: I'm missing cshtml here... although I guess my web.config contains the right entry:

<compilation debug="true" targetFramework="4.0">
  <buildProviders>
    <add extension=".cshtml" type="Nancy.ViewEngines.Razor.BuildProviders.NancyCSharpRazorBuildProvider, Nancy.ViewEngines.Razor.BuildProviders" />
    <add extension=".vbhtml" type="Nancy.ViewEngines.Razor.BuildProviders.NancyVisualBasicRazorBuildProvider, Nancy.ViewEngines.Razor.BuildProviders" />
  </buildProviders>


</compilation>

The Nancy Module behind works fine: I have added the route

        Get["/api/v1/admin/clients/{id}"] = parameters => {
            return "Hello";
        };

and get the "Hello"...

Any hints?

هل كانت مفيدة؟

المحلول

You haven't deployed the Nancy razor package, or it can't load it for some reason (dependency missing maybe), that's why it does't list the file types.

نصائح أخرى

Close, but the Nancy razor packag wasn't missing. The Nancy razor package was deployed. The only thing missing was System.Razor.dll. I deployed that too and done :)

I find this issue still happening with the Nancy template projects. You need to remove and re-add the Nancy nuget references. Enabling package restore doesn't seem to be enough.

I ran into this problem self-hosting Nancy from a console application which referenced a separate DLL "web" project. The razor DLLs weren't being copied to the output folder even though the console project referenced the web project, and the web project references the appropriate razor libraries.

Since the razor DLLs are loaded dynamically, they were not copied to console's output folder. More discussion on the underlying issue here: Is "Copy Local" transitive for project references?

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top