zoukankan      html  css  js  c++  java
  • ASP.NET 请求处理 四 (Controller基本特性)

    public class TestController : Controller
        {
            [ThreadStatic]
            static ThreadInfo obj;
    
            [HttpGet]
            public string Index()
            {
                return "123456";
            }
    
            [HttpGet]
            public string bbb()
            {
                bool bnew = obj == null;
                if (bnew)
                {
                    obj = new ThreadInfo();
                    obj.id = Thread.CurrentThread.ManagedThreadId.ToString();
                    obj.name = "controller hash="+this.GetHashCode();
                }
                return bnew+"______class info{ hash:"+this.GetHashCode().ToString()
                    +",thread id:"+Thread.CurrentThread.ManagedThreadId.ToString()
                    +",_________"+obj.ToString();
            }
        }
    
        class ThreadInfo
        {
            public String id;
            public String name;
            public override string ToString()
            {
                return "threadinfo{id:"+id+",name:"+name+",thread obj hash:"+GetHashCode().ToString();
            }
        }
        //True______class info{ hash:26130175,thread id:67,_________threadinfo{id:67,name:controller hash=26130175,thread obj hash:19998225
        //False______class info{ hash:23697479,thread id:67,_________threadinfo{id:67,name:controller hash=26130175,thread obj hash:19998225
        //True______class info{ hash:55575390,thread id:74,_________threadinfo{id:74,name:controller hash=55575390,thread obj hash:18085517
        //False______class info{ hash:7922750,thread id:74,_________threadinfo{id:74,name:controller hash=55575390,thread obj hash:18085517
        //False______class info{ hash:26960933,thread id:67,_________threadinfo{id:67,name:controller hash=26130175,thread obj hash:19998225
        //False______class info{ hash:64947243,thread id:67,_________threadinfo{id:67,name:controller hash=26130175,thread obj hash:19998225

    1.默认每次请求都会生成一个controller实例 (这个和java-spring里面默认的controller模式有区别)

    2.请求会从线程池中取线程来处理

  • 相关阅读:
    CSS3 not
    rxjs1
    Angular 2 组件之间如何通信?
    开发去。。
    补零补零
    MySQL数据库从复制及企业配置实践
    互联网中接口安全解决方案
    redis服务打不开--解决办法
    搭建Git服务器
    git将当前分支上修改的东西转移到新建分支
  • 原文地址:https://www.cnblogs.com/dint/p/14067352.html
Copyright © 2011-2022 走看看