。net 工作中的遇到常见的一些,重复代码,未完待续

分页sql 

select * from
(
select row_number() over(order by 总额 desc) as rownumber, t.RealName,t.Name, t.提交数, t.总额 from
(select  b.RealName,c.Name,count(*) 提交数,sum(a.Money) 总额 from YX_SALE a left join Tb_Common_User b on a.WorkNO=b.WorkNO left join WFT_Network c on a.NetworkNO=c.NetworkNO  where b.BankSear='003059105285' and a.ProductType='1'
group by b.RealName,c.Name) t 
) temp where rownumber between (1-1)*6 and 1*6

一般处理程序 

  protected HttpRequest Request;
        protected HttpResponse Response;
        protected HttpSessionState Session;
        protected HttpServerUtility Server;
        protected HttpApplicationState Application = HttpContext.Current.Application;
        protected dbo conn = common.make();
        protected JsonConvert<object> jc = new JsonConvert<object>();
        //protected UserInfo ui = new UserInfo();

        public void ProcessRequest(HttpContext context)
        {
            //不让浏览器缓存
            context.Response.Buffer = true;
            context.Response.ExpiresAbsolute = DateTime.Now.AddDays(-1);
            context.Response.AddHeader("pragma", "no-cache");
            context.Response.AddHeader("cache-control", "");
            context.Response.CacheControl = "no-cache";
            context.Response.ContentType = "text/plain";

            #region 设置允许跨域,允许复杂请求
            //header("Access-Control-Allow-Origin: *"); # 跨域处理
            context.Response.AddHeader("Access-Control-Allow-Origin", "*");
            if (context.Request.HttpMethod == "OPTIONS")
            {
                context.Response.AddHeader("Access-Control-Allow-Methods", "GET,POST,PUT,DELETE,PATCH,OPTIONS");
                context.Response.AddHeader("Access-Control-Allow-Headers", "Content-Type, Accept, Authorization");
                //header('Access-Control-Allow-Headers:x-requested-with'); //php设置
                //response.addHeader("Access-Control-Allow-Origin", "*");
                context.Response.AddHeader("Access-Control-Allow-Headers", "x-requested-with");
                //HttpContext.Current.Response.AddHeader("Access-Control-Max-Age", "1728000");
                context.Response.End();
            }
            #endregion

            Request = context.Request;
            Response = context.Response;
            Session = context.Session;
            Server = context.Server;

            string method = context.Request["Method"].ToString();
            MethodInfo methodInfo = this.GetType().GetMethod(method);
            methodInfo.Invoke(this, null);
        }

asp.net一份配置文件,链接sql 写法

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <appSettings>
    <add key="IsBank" value="false" />
  </appSettings>
  <connectionStrings>
    <clear />
    <!-- 
   Access的写法:
        <add name="ConnectionSetting" connectionString="database/gis.mdb"
        providerName="OleDB" />
        
   Oracle的写法:
        <add name="ConnectionSetting" connectionString="Provider=MSDAORA.1;Data Source=Wish;Persist Security Info=False;User ID=scott;password=tiger;"
        providerName="Oracle" />
    -->
    <add name="ConnectionSetting" connectionString="Server=www.xxx.xxx,56001;uid=sa;pwd=*****;database=******pooling=true;Max Pool Size = 2000;" providerName="SQLServer" />
  </connectionStrings>
  <system.web>
    <!--<sessionState mode="StateServer" stateConnectionString="tcpip=127.0.0.1:42424" timeout="30"></sessionState>-->
    <httpRuntime maxRequestLength="15360" useFullyQualifiedRedirectUrl="true" executionTimeout="6000" minFreeThreads="8" minLocalRequestFreeThreads="4" requestValidationMode="2.0" appRequestQueueLimit="100" enableVersionHeader="true" />
    <pages enableViewStateMac="false" enableSessionState="true" validateRequest="false" enableEventValidation="false" controlRenderingCompatibilityVersion="4.0" clientIDMode="AutoID">
      <controls>
        <add namespace="AjaxControlToolkit" assembly="AjaxControlToolkit" tagPrefix="ajaxToolkit" />
        <add tagPrefix="webdiyer" namespace="Wuqi.Webdiyer" assembly="AspNetPager" />
        <add tagPrefix="anthem" namespace="Anthem" assembly="Anthem" />
      </controls>
    </pages>
    <!--  动态调试编译
          设置 compilation debug="true" 以启用 ASPX 调试。否则,将此值设置为
          false 将提高此应用程序的运行时性能。
          设置 compilation debug="true" 以将调试符号(.pdb 信息)
          插入到编译页中。因为这将创建执行起来
          较慢的大文件,所以应该只在调试时将此值设置为 true,而在所有其他时候都设置为
          false。有关更多信息,请参考有关
          调试 ASP.NET 文件的文档。
    -->
    <compilation defaultLanguage="c#" debug="true" targetFramework="4.0">
      <assemblies>
        <add assembly="System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A" />
        <add assembly="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
        <add assembly="System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
        <add assembly="System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A" />
        <add assembly="System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A" />
        <add assembly="System.Xml, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
        <add assembly="System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
        <add assembly="System.Configuration, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A" />
        <add assembly="System.Data.OracleClient, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
      </assemblies>
    </compilation>
    <!--  自定义错误信息
          设置 customErrors mode="On" 或 "RemoteOnly" 以启用自定义错误信息,或设置为 "Off" 以禁用自定义错误信息。 
          为每个要处理的错误添加 <error> 标记。

          "On" 始终显示自定义(友好的)信息。
          "Off" 始终显示详细的 ASP.NET 错误信息。
          "RemoteOnly" 只对不在本地 Web 服务器上运行的
           用户显示自定义(友好的)信息。出于安全目的,建议使用此设置,以便 
           不向远程客户端显示应用程序的详细信息。
    -->
    <customErrors mode="Off" />
    <!--  身份验证 
          此节设置应用程序的身份验证策略。可能的模式是 "Windows"、 
          "Forms"、 "Passport" 和 "None"

          "None" 不执行身份验证。 
          "Windows" IIS 根据应用程序的设置执行身份验证 
            (基本、简要或集成 Windows)。在 IIS 中必须禁用匿名访问。
          "Forms" 您为用户提供一个输入凭据的自定义窗体(Web 页),然后 
           在您的应用程序中验证他们的身份。用户凭据标记存储在 Cookie 中。
          "Passport" 身份验证是通过 Microsoft 的集中身份验证服务执行的,
           它为成员站点提供单独登录和核心配置文件服务。
    -->
    <authentication mode="Forms">
      <forms name="j****t" loginUrl="/login.aspx" defaultUrl="login.aspx" protection="All">
      </forms>
    </authentication>
    <authorization>
      <allow users="*" />
    </authorization>
    <!--  应用程序级别跟踪记录
          应用程序级别跟踪为应用程序中的每一页启用跟踪日志输出。
          设置 trace enabled="true" 可以启用应用程序跟踪记录。如果 pageOutput="true",则
          在每一页的底部显示跟踪信息。否则,可以通过浏览 Web 应用程序
           根目录中的 "trace.axd" 页来查看
          应用程序跟踪日志。
    -->
    <trace enabled="false" requestLimit="10" pageOutput="false" traceMode="SortByTime" localOnly="true" />
    <!--  会话状态设置
          默认情况下,ASP.NET 使用 Cookie 来标识哪些请求属于特定的会话。
          如果 Cookie 不可用,则可以通过将会话标识符添加到 URL 来跟踪会话。
         若要禁用 Cookie,请设置 sessionState cookieless="true"。
    -->
    <sessionState mode="InProc" stateConnectionString="tcpip=127.0.0.1:42424" sqlConnectionString="data source=127.0.0.1;Trusted_Connection=yes" cookieless="false" timeout="20" />
    <!--  全球化
          此节设置应用程序的全球化设置。
    -->
    <!--
    <globalization fileEncoding="gb2312" requestEncoding="gb2312" responseEncoding="gb2312" culture="zh-CN" />
    加上上面这个,echarts中文就会乱码
    -->
    <httpHandlers>
      <add verb="POST,GET" path="ajax/*.ashx" type="Ajax.PageHandlerFactory, Ajax" />
    </httpHandlers>
    <xhtmlConformance mode="Legacy" />
  </system.web>
  <system.webServer>
    <!--为了支持跨域-->
    <httpProtocol>
      <customHeaders>
        <add name="Access-Control-Allow-Origin" value="*"/>
        <add name="Access-Control-Allow-Headers" value="X-Requested-With"/>
        <add name="Access-Control-Allow-Methods" value="GET, POST, PUT, DELETE, OPTIONS"/>
      </customHeaders>
    </httpProtocol>
    <validation validateIntegratedModeConfiguration="false" />
    <defaultDocument>
      <files>
        <remove value="default.aspx" />
        <remove value="iisstart.htm" />
        <remove value="index.html" />
        <remove value="index.htm" />
        <remove value="Default.asp" />
        <remove value="Default.htm" />
        <add value="Login.aspx" />
      </files>
    </defaultDocument>

    <modules runAllManagedModulesForAllRequests="true">
            <remove name="Session" /><!--此处删除Session是为了Url重写删除后无法使用Session因此重新添加了一个Session-->
            <add name="Session" type="System.Web.SessionState.SessionStateModule"/>
         
    </modules>

  </system.webServer>
  <system.codedom>
    <compilers>
      <compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CSharp.CSharpCodeProvider, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" warningLevel="4" compilerOptions="/d:DEBUG;TRACE">
        <providerOption name="CompilerVersion" value="v4.0" />
      </compiler>
    </compilers>
  </system.codedom>
  <location path="Web">
    <system.web>
      <authorization>
        <deny users="?" />
      </authorization>
    </system.web>
  </location>
</configuration>

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章