加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

ASP.NET网络表单的Nancy路由

发布时间:2020-12-16 09:47:36 所属栏目:asp.Net 来源:网络整理
导读:我一直在尝试在我的webforms项目上实现Nancy.我读过这本指南: https://github.com/NancyFx/Nancy/wiki/Hosting-nancy-with-asp.net 我已将此添加到我的配置中: system.webServer handlers add name="Nancy" verb="*" type="Nancy.Hosting.Aspnet.NancyHttp
我一直在尝试在我的webforms项目上实现Nancy.我读过这本指南:
https://github.com/NancyFx/Nancy/wiki/Hosting-nancy-with-asp.net

我已将此添加到我的配置中:

<system.webServer>
    <handlers>
        <add name="Nancy" verb="*" type="Nancy.Hosting.Aspnet.NancyHttpRequestHandler" path="nancy/*" />
    </handler>
</system.webServer>

我创建了一个带有web.config文件的’/ nancy’文件夹:

<?xml version="1.0"?>
<configuration>
    <system.web>
        <httpHandlers>
        <add verb="*" type="Nancy.Hosting.Aspnet.NancyHttpRequestHandler" path="*"/>
     </httpHandlers>
    </system.web>
</configuration>

我有以下C#代码:

public class TestApi : Nancy.NancyModule
{
    public TestApi()
        : base("/nancy")
    {
        Get["/ok"] = parameters =>
                            {
                                return "Ok";
                            };
    }
}

这在访问’/ nancy / ok’时有效
但是当我将’Get [“/ ok”]’更改为’Get [“/ ok / ok”]’并访问’/ nancy / ok / ok’时,我得到了404 Not Found(小巨魔图像和所有)

编辑*
如果我把它留在’Get [“/ ok”]’并访问/ ok / ok / ok我得到“Ok”回来……

有什么想法我不能做出更具体的路线?

问候Mads

解决方法

根据您的路由判断您希望在url / nancy下运行Nancy,因此任何url都由Nancy处理,而根目录上定义的任何其他内容将继续在ASP.Net Web Forms下运行.

如果是这种情况,问题是您需要将处理程序包装在< location>中.标签:

<location path="nancy">
  <system.web>
    <compilation debug="true" targetFramework="4.0" />
    <httpHandlers>
      <add verb="*" type="Nancy.Hosting.Aspnet.NancyHttpRequestHandler" path="*"/>
    </httpHandlers>
  </system.web>

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

这允许Nancy处理在位置/南希下调用的所有请求(由path =“*”定义).

此信息可以在您将Nancy添加到现有站点下链接到的链接中找到

https://github.com/NancyFx/Nancy/wiki/Hosting-nancy-with-asp.net#adding-nancy-to-an-existing-site

^直接链接到特定标题.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读