zoukankan      html  css  js  c++  java
  • Nancyfx框架在传统Webform项目中的应用

    最近有个老项目需要做一个需求更迭,老项目是基于传统的webform项目的 为了更好的前后台交互,决定引入Nancyfx框架

    关于Nancyfx框架框架是啥就不多介绍了 总的来说是一款轻量级的web框架,路由规则相当丰富

    第一步:引用相关Nacnyfx依赖

    Install-Package Nancy -Version 1.4.5

    Install-Package Nancy.Hosting.Aspnet -Version 1.4.1

    第二步 Nancyfx 路由配置

    由于是基于现有的webform系统,配置需要特别注意

    在web.config中添加 location标签 path="nancy" 表明 处理nancyfx处理的路由路径 ,类似mvc系统中的 Area名称

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

    第三步:使用Nancyfx开发后台接口

     好啦 这样就可以愉快的使用nancyfx啦

     新建Home类并且继承自NancyModule

     public class Home:NancyModule
        {
            public Home():base("nancy")
            {
                Get["/home"] = x => "hello";
                Get["/cn"] = x =>
                {
                    return Response.AsText("呵呵,中文不乱码了!!", "text/html;charset=UTF-8");//中文不乱码了!!
                };
            }
        }

    然后就可以跑起来啦

    访问地址  http://localhost:49799/nancy/home   返回hello

    访问地址  http://localhost:49799/nancy/cn    返回    呵呵,中文不乱码了!

  • 相关阅读:
    PCL:描述三维离散点的ROPS特征(Code)
    veket智能机器人
    三维重建:SLAM的粒度和工程化问题
    DNN:逻辑回归与 SoftMax 回归方法
    人工智能:一种现代方法 第四版 翻译序言
    编程低级错误记录
    apache服务器配置防盗链(centos7)
    Linux下命令行中的复制和粘贴
    rm: cannot remove `libtoolT’: No such file or directory
    switch范围判断
  • 原文地址:https://www.cnblogs.com/yushuo/p/10276375.html
Copyright © 2011-2022 走看看