NancyFx / Nancy

Lightweight, low-ceremony, framework for building HTTP based services on .Net and Mono
http://nancyfx.org
MIT License
7.16k stars 1.47k forks source link

Using Nancy 2 with Razor? #2839

Open bonesoul opened 6 years ago

bonesoul commented 6 years ago

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

jdixon-86 commented 6 years ago

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

dealproc commented 6 years ago

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.

bonesoul commented 6 years ago

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.

jdixon-86 commented 6 years ago

@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?

bonesoul commented 6 years ago

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 commented 6 years ago

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.

jdixon-86 commented 6 years ago

@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.

bonesoul commented 6 years ago

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 commented 6 years ago

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

teedty1 commented 5 years ago

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

JTrotta commented 4 years ago

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

grumpydev commented 4 years ago

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