zoukankan      html  css  js  c++  java
  • ASP.NET网站发布时的那些坑

    开发工具:VS2010,MVC4.0,SQLSERVER2008

    服务器:Windows server 2012,IIS8,SQLSERVER2012

    一、发布后,每个页面第一次打开都很卡,50秒或更长,第二次打开就很快了

    估计原因:编译速度慢,但在有VS环境的机器上发布没有这么卡

    解决办法:

    • 使用高版本的VS,“在发布期间预编译”;
    • 使用IIS8的Application Initialization功能

    1. 使用VS2017“在发布期间预编译”

    123456

    发布时遇到一个报错:

    在应用程序级别之外使用注册为 allowDefinition='MachineToApplication' 的节是错误的。如果在 IIS 中没有将虚拟目录配置为应用程序,则可能导致此错误。

    解决办法:发布时注释web.config中的以下代码

    <!--<authentication mode="Forms">
        <forms loginUrl="~/Account/Login" timeout="2880" />
    </authentication>-->

    2. 使用IIS8的Application Initialization功能

    http://jingyan.baidu.com/article/c843ea0bb6c13877931e4a2e.html

    二、ASP.NET session 频繁丢失问题

    问题现象:登录后30秒左右会话丢失,需要重新登录。

    解决办法:ASP.NET有几种会话状态模式,默认为“InProc模式”,改为“StateServer模式”,问题解除。

    1. off模式

    即关闭Session。

    全站关闭Session可在Web.Config文件中的<system.web>节中写入:

    <sessionState mode="off">

    要在某个页面上关闭Session,可在页面上添加:

    <%@ Page EnableSessionState="false" %>

    2. InProc模式(缺省模式)

    如果未在Web.config文件中配置SessionState Mode,默认即是InProc模式。

    如果要定制InProc模式的参数,需要写入Web.config文件,例如:

    <sessionState mode="InProc" cookieless="false" timeout="20" />

    cookieless设置是否允许不使用Cookie,timeout设置超时时间,单位为分钟。

    InProc模式依赖于 ASP.NET进程, 当IIS进程崩溃或者重启时,保存在进程中的会话状态会丢失。

    3. StateServer模式

    StateServer模式是将会话数据存储到单独的内存缓冲区中,由一个Windows服务“ASP.NET State Service ”(需要在windows服务中开启)来控制这个缓冲区,需要设置stateConnectionString:

    <sessionState mode="StateServer"  stateConnectionString="tcpip=127.0.0.1:42424" timeout="20" />

    使用StateServer模式时,所有需要保存在Session中的类,都要加上可序列化的特性:

    [Serializable]
    public class SomeClass { }

    StateServer模式的优点是独立于IIS进程,IIS应用程序的重启不影响会话数据。

    4. SQLServer模式

    使用SQL Server来保存Session,即使IIS重启,Session仍然不会丢失。需要先创建ASPState数据库。具体方法可在网上查询。


  • 相关阅读:
    1451. Rearrange Words in a Sentence
    1450. Number of Students Doing Homework at a Given Time
    1452. People Whose List of Favorite Companies Is Not a Subset of Another List
    1447. Simplified Fractions
    1446. Consecutive Characters
    1448. Count Good Nodes in Binary Tree
    709. To Lower Case
    211. Add and Search Word
    918. Maximum Sum Circular Subarray
    lua 时间戳和时间互转
  • 原文地址:https://www.cnblogs.com/tuty/p/6664279.html
Copyright © 2011-2022 走看看