Nancy.Net45 1.0.0

dotnet add package Nancy.Net45 --version 1.0.0                
NuGet\Install-Package Nancy.Net45 -Version 1.0.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Nancy.Net45" Version="1.0.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Nancy.Net45 --version 1.0.0                
#r "nuget: Nancy.Net45, 1.0.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Nancy.Net45 as a Cake Addin
#addin nuget:?package=Nancy.Net45&version=1.0.0

// Install Nancy.Net45 as a Cake Tool
#tool nuget:?package=Nancy.Net45&version=1.0.0                
static void Main(string[] args)
{
     var url = "http://localhost/";
     var uri = new Uri(url);
     var host = new NancyHost(uri);
     host.Start();
     Console.WriteLine($"start {url}");
     Console.ReadKey();
}

public class Home : NancyModule
    {
        public Home() : base("/Home")
        {
            //拦截器
            Before += ctx =>
            {
                if (Request.Query.a != null)
                {
                    var res = new Response();
                    return res;
                }

                return null;
            };

            Get("/", _ =>
            {

                var a = Request.Query.name;
                //return Response.AsText("会乱码吗");
                //return Response.AsText("会乱码吗, "text/plain;charset=UTF-8");
                return "不会乱码";
            });

            Get("/Index", _ =>
            {

                var list = new List<string>() { "list1", "list2", "list3" };
                var model = new { list = list, a = "你好", b = "很不好", abc = "abc你好" };
                return View["Index.html", model];
            });

            Get("Test", _ =>
            {
                return View["Test.html"];
            });

            Get("Data", _ =>
            {
                var data = new { a = "你好", b = 1 };
                return Response.AsJson(data);
            });

            Post("Upload", _ =>
            {
                var uploadDirectory = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Content/Upload");
                if (!Directory.Exists(uploadDirectory))
                {
                    Directory.CreateDirectory(uploadDirectory);
                }
                var files = Request.Files;
                foreach (var file in files)
                {
                    var filename = Path.Combine(uploadDirectory, file.Name);
                    using (var fileStream = new FileStream(filename, FileMode.Create))
                    {
                        file.Value.CopyTo(fileStream);
                    }
                }
                return Response.AsText("ok");
            });

            Get("Cookie", _ =>
            {
                var res = new Response();
                res.ContentType = "text/plain;charset=UTF-8";
                res.Contents = stream =>
                {
                    var data = Encoding.UTF8.GetBytes("你好");
                    stream.Write(data, 0, data.Length);
                };
                return res.WithCookie("a", "45646");
            });

            Get("Abc", _ =>
            {
                DynamicDictionary dyDict = Request.Query;
                var dict = dyDict.ToDictionary();
                foreach (var key in dict.Keys)
                {
                    Console.WriteLine(key);
                    Console.WriteLine(dict[key]);
                    Console.WriteLine(dict[key].GetType());
                }
                return Response.AsText("111");
            });

            Get("Bind", _ =>
            {
                var p = this.Bind<People>();
                Console.WriteLine(p.Id);
                Console.WriteLine(p.Name);
                return Response.AsText("111");
            });

            Get("error", _ =>
            {
                throw new Exception("发生异常");
                return Response.AsText("error");

            });

            Get("/all", par =>
            {
                return "你好";
            });

            Get("/all2", par =>
            {
                return "all2";
            });
        }
Product Compatible and additional computed target framework versions.
.NET Framework net45 is compatible.  net451 was computed.  net452 was computed.  net46 was computed.  net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

This package has no dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.0 389 8/27/2021