Nancyfx Test Webpage 404 error page

Created on 23 Aug 2016  Â·  28Comments  Â·  Source: NancyFx/Nancy

Description

404 - NotFound

The resource you have requested cannot be found.**

Steps to Reproduce

I have added the Nancyfx, Nancy.Hosting.Asp.net, and the Nancy.BootStrappers.StructureMap.

Below is the module I have

using Nancy;

namespace NancyExample
{
    public class Class1 : NancyModule
    {
        public Class1()
        {
            Get["/status"] = _ => "Hello world";


        }
    }
}

This is just a test case I am trying to implement something larger but I can't seem to get this to work.

System Configuration

  • Nancy version: latest
  • Nancy host

    • [X] ASP.NET

  • Environment (Operating system, version and so on): Windows 10 and using Visual studio
  • .NET Framework version: 4.5.2

@khellang

Most helpful comment

Maybe I missed something in the docs but a big catch here is that your NancyModule needs to be public.
Got bitten by that.

All 28 comments

Is this a Nancy 404 or an IIS/ASP.NET 404? Where is this server running (URL) and how are you making the request?

I believe this is a Nancy 404 error. I'm using "/status" to generate a page that says "hello world" after the given url in picture.

capture1

I don't get it. You're not hitting http://localhost:64723/status. You're hitting http://localhost:64723. No wonder you're getting a 404 :smile:

Yes I'm also doing that
capture1

If you remove the leading slash:

-    Get["/status"] = _ => "Hello world";
+    Get["status"] = _ => "Hello world";

Does that work?

Also, can you post your web.config?

The leading slash shouldn't have an impact here. I am guessing there is more to the story than what has been said. Is the module the _exact_ module you are using? Are there name space differences? And so on. Usually problems are described using _similar_ but not _identical_ code and details gets lost. The setup you describe is the absolute most common setup for a Nancy application and one that we use over and over again in our sample applications. I'd say it's the most tested execution path in the entire code base, hence why I think there is something else that is not mentioned but having an impact. 😄

<?xml version="1.0"?>
<configuration>
  <system.web>
    <httpHandlers>
      <add verb="*" type="Nancy.Hosting.Aspnet.NancyHttpRequestHandler" path="*"/>
    </httpHandlers>
    <compilation debug="true"/>
  </system.web>
  <system.webServer>
    <validation validateIntegratedModeConfiguration="false"/>
    <httpErrors existingResponse="PassThrough"/>
    <handlers>
      <add name="Nancy" verb="*" type="Nancy.Hosting.Aspnet.NancyHttpRequestHandler" path="*"/>
    </handlers>
  </system.webServer>
</configuration>`

I followed an online instruction video from youtube. I'm using visual studios and I installed the packages using Nuget, Nancy, Nancy.Hosting.aspnet, and Nancy.BootStrappers.StructureMap. I also used a asp.net web application where I made the template empty. After that i just added the code I changed nothing else.

@Elicomp17 any chance you could zip your project and link it here? Or upload it to a github repo (even better) ?

Also, wrap code in triple back-quote ` and it will be highlighted properly

WebApplication1.zip
Do you also need the IIS file???

I downloaded and ran your application

image

¯_(ツ)_/¯

Could it be a firewall got any hunches on what it could be?
or some type of internet or chrome explorer setting...

Should just work. There should not be any firewall issues if you are running it all on your local machine. Try manually deleting your bin folder and rebuild (don't just do a clean)

okay as in delete everything in it?

Yep

capture

@thecodejunkie
Well I deleted content in bin folder and did a rebuild this is what I got afterwards

Does it matter which Net framework I use
@khellang
@thecodejunkie

Your solution (the one you linked) worked perfectly on my machine without any changes at all. It is running Nancy on your machine .. or you wouldn't have gotten the 404 page.. the problem is that the module discovery does not seem to be picking up the module on your machine, which is strange since it's in the same application. Might be a security thing on your box? Type scanning uses reflection in this case.

"Might be a security thing on your box? Type scanning uses reflection in this case."

Can you clarify what this part means?
@thecodejunkie

On the full-framework (not .net core) Nancy uses reflection to scan the current AppDomain to find all types that inherits from NancyModule. Sounds like this is failing for some reason.

Also, try removing the Nancy.Bootstrappers.StructureMap.1.4.3 because right now you're not really using it (nancy is internally) so remove it to reduce the number of moving parts that could be the potential source of your problem

That also Did not work thanks for the help I really appreciate it. I can't figure out whats wrong with it I tried everything you said. Strange how it works for you and not me. @thecodejunkie

Figured it out for some reason the .dll files for the project were missing or were not generated. I ran the solution on a different computer and it generated files that were not in by "obj" files or my "debug" folder . Visual studio assisted in telling me which files were missing.
I still can't figure out why though
@khellang
@thecodejunkie

Maybe I missed something in the docs but a big catch here is that your NancyModule needs to be public.
Got bitten by that.

Thanks @jods4; that fixed the issue for me! I'm glad you decided to add a late addition to the thread.

For me was really helpfull additional configuration at Web.config for IIS 7:

<system.webServer>
    <modules runAllManagedModulesForAllRequests="true" />
    <validation validateIntegratedModeConfiguration="false" />
    <handlers>
      <add path="*" name="Nancy" type="Nancy.Hosting.Aspnet.NancyHttpRequestHandler" verb="*" preCondition="integratedMode" resourceType="Unspecified" allowPathInfo="true" />
    </handlers>
  </system.webServer>

Hope someone else it will help.

Can sombody please help me with this, I cant figure out what im doining wrong.

`using Nancy;
using Nancy.Hosting.Self;
using System;

namespace TestNancyweb
{
public class Module : NancyModule
{
public void SetRoutes()
{
Get("/", x => {
return string.Concat("Hello ");
});
}
}
}

namespace TestNancy
{
class Program
{

    static void Main(string[] args)
    {
        String url = "http://127.0.0.1:9998";
        HostConfiguration config = new HostConfiguration();
        config.UrlReservations.CreateAutomatically = true;

        var uri = new Uri(url);


        using (var host = new NancyHost(config, uri))
        {
            host.Start();
            Console.WriteLine("Running on " + uri);
            Console.ReadLine();

            while(true)
            {
                //logger.Debug("API heartbeat");
                System.Threading.Thread.Sleep(1000);

            }
        }
    }
}

}

`

Was this page helpful?
0 / 5 - 0 ratings