在IIS8 Express上运行ServiceStack时出现404 Not Found错误

时间:2014-06-21 21:15:55

标签: servicestack

关于这个帖子:404 Not found 我仍然在Win 8.1 - VS 2013-1

上遇到此问题
<!--<system.webServer>
   <validation validateIntegratedModeConfiguration="false" />
</system.webServer>-->
<location path="api">
<system.web>
  <httpHandlers>
    <add path="*" type="ServiceStack.HttpHandlerFactory, ServiceStack" verb="*" />
  </httpHandlers>
</system.web>

<system.webServer>
  <validation validateIntegratedModeConfiguration="false" />
  <modules runAllManagedModulesForAllRequests="true" />
  <handlers>
    <add path="*" name="ServiceStack.Factory" type="ServiceStack.HttpHandlerFactory, ServiceStack" verb="*" preCondition="integratedMode" resourceType="Unspecified" allowPathInfo="true" />
  </handlers>
</system.webServer>

public class HelloAppHost : AppHostBase
{

        /// <summary>
        /// Initializes a new instance of your ServiceStack application, with the specified name and assembly containing the services.
        /// </summary>
        public HelloAppHost() : base("Hello Web Services", typeof(HelloService).Assembly) { }

        /// <summary>
        /// Configure the container with the necessary routes for your ServiceStack application.
        /// </summary>
        /// <param name="container">The built-in IoC used with ServiceStack.</param>
        public override void Configure(Container container)
        {
            //Register user-defined REST-ful urls. You can access the service at the url similar to the following.
            //http://localhost/ServiceStack.Hello/servicestack/hello or http://localhost/ServiceStack.Hello/servicestack/hello/John%20Doe
            //You can change /servicestack/ to a custom path in the web.config.
            SetConfig(new HostConfig
            {
                HandlerFactoryPath = "api"
            });
            SetConfig(new HostConfig { DebugMode = true });

            Routes
              .Add<Hello>("/hello")
              .Add<Hello>("/hello/{Name}");
        }

}

当我取消注释第二个system.webServer标记时,我只从api路由获取HandlerNotFound Exceptions。当我删除web.config中的位置标记时,会发生相同的错误。

就像它现在一样有效......

任何有助于澄清的帮助, 谢谢诺伯特

1 个答案:

答案 0 :(得分:1)

您需要更改以下内容:

SetConfig(new HostConfig
{
    HandlerFactoryPath = "api"
});
SetConfig(new HostConfig { DebugMode = true });

SetConfig(new HostConfig
{
   HandlerFactoryPath = "/api",
   DebugMode = true
};

只是一个猜测,但你的第二个HostConfig实例可能会覆盖第一个实例。