Nancy icon indicating copy to clipboard operation
Nancy copied to clipboard

Using Nancy 2 with Razor?

Open bonesoul opened this issue 7 years ago • 12 comments

I'm trying to get Nancy2 clinteastwood with Razor but couldn't find any guides for so? Any directions?

bonesoul avatar Dec 21 '17 14:12 bonesoul

I believe it is the same as Nancy1 as far as Razor is concerned. I would look at my issue here that others have experienced with Razor before going down that road though: #2731

jdixon-86 avatar Dec 23 '17 15:12 jdixon-86

Been doing so (Razor/2.0.0-ClintEastwood).... been fine so far that I recollect. I have 1-2 things in production (internal-only systems) that have been fine.

dealproc avatar Dec 26 '17 06:12 dealproc

I've been uzing Razor with 1.x series but have no idea how to do it with 2.x :/ Because i can't find propoper documentation for 2.x.

bonesoul avatar Dec 26 '17 09:12 bonesoul

@dealproc there is an issue when the application starts if there are multiple concurrent requests at the same time it can cause a deadlock situation because it caches an assembly that appears to be invalid. The issue is reproducible but I only run into customers complaining about it every 1-2 months on my end. Most know to recycle the application pool again.

@bonesoul what issue are you running into?

jdixon-86 avatar Dec 26 '17 13:12 jdixon-86

I referenced Nancy.ViewEngines.Razor.

When i navigate to my webserver; cshtml files are not checked even;

Could not locate your error view! Details: 
Unable to locate requested view

 • Name: error
 • Root path: E:\Coding\CoiniumServ\build\bin\Debug\netcoreapp2.0\web\default
 • Supported extensions: 
  - sshtml
  - html
  - htm
 • Inspected locations: 
  - views//error-
  - views//error
  - /error-
  - /error
  - views/error-
  - views/error
  - error-
  - error

If you were expecting raw data back, make sure you set the 'Accept'-header of the request to correct format, for example 'application/json'

bonesoul avatar Dec 27 '17 10:12 bonesoul

I'm trying to get Razor working with Nancy & dotnet core. Note that I'm using in-process nancy in an existing network server code not a new aspnet core website project.

  • here's my (standalone) webserver code; https://github.com/bonesoul/CoiniumServ/blob/feature/dotnet-core/src/CoiniumServ/Server/Web/WebServer.cs
  • nancybootstrapper: https://github.com/bonesoul/CoiniumServ/blob/feature/dotnet-core/src/CoiniumServ/Server/Web/NancyBootstrapper.cs
  • rootpathprovider: https://github.com/bonesoul/CoiniumServ/blob/feature/dotnet-core/src/CoiniumServ/Server/Web/RootPathProvider.cs

bonesoul avatar Dec 27 '17 10:12 bonesoul

@bonesoul I have encountered this issue before. Basically it isn't recognizing the .cshtml extension. I'm trying to recall what it was but I think it had something to do with the System.Web.Razor not being set to Copy Local and the same for Nancy.ViewEngines.Razor.

I'm trying to look through my past issues for my project and finding where I documented what this was.

jdixon-86 avatar Dec 27 '17 19:12 jdixon-86

before nancy 2 & dotnet core update i was using this;

  <Target Name="AfterBuild">
    <Copy SourceFiles="$(SolutionDir)/packages/Nancy.Viewengines.Razor.1.4.3/BuildProviders/Nancy.ViewEngines.Razor.BuildProviders.dll" DestinationFolder="$(OutDir)" />
    <Copy SourceFiles="$(SolutionDir)/packages/Nancy.Viewengines.Razor.1.4.3/lib/net40/Nancy.ViewEngines.Razor.dll" DestinationFolder="$(OutDir)" />
  </Target>

changed it to

  <Target Name="Copy" AfterTargets="CoreCompile">
    <Copy SourceFiles="$(SolutionDir)/packages/nancy.viewengines.razor/2.0.0-clinteastwood/lib/net452/Nancy.ViewEngines.Razor.dll" DestinationFolder="$(OutDir)" />	
  </Target> 

but i can't find a BuildProviders folder in new 2.0.0-clienteastwood nancy.viewengines.razor package.

maybe related to this https://github.com/NancyFx/Nancy/blob/master/src/Nancy.ViewEngines.Razor/targets/Nancy.ViewEngines.Razor.targets

bonesoul avatar Jan 04 '18 13:01 bonesoul

I've added the package for Nancy.ViewEngines.Razor.BuildProviders-clienteastwood but still no luck.

https://github.com/NancyFx/Nancy/tree/master/src/Nancy.ViewEngines.Razor.BuildProviders

bonesoul avatar Jan 04 '18 13:01 bonesoul

I was able to get a Razor ViewEngine working in my .net core 2.2 project. If this is helpful to anyone please feel free to use it. Also, if anyone sees anything that I'm doing wrong I'd love to hear from you.

https://gist.github.com/teedty1/a505b2a4fb2c48658d127d5d4682628a

teedty1 avatar Jun 26 '19 15:06 teedty1

Any news about this? Still not working on dot net core 3.1

JTrotta avatar Mar 02 '20 20:03 JTrotta

@JTrotta did you look at what @teedty1 posted? Unless anyone volunteers to get this working it's unlikely this will ever be properly supported.

grumpydev avatar Mar 02 '20 20:03 grumpydev