请问各位高手,怎么可以让.net做出来的网站访问速度更快?用什么方法比较好呢?希望大家多提意见,最好能有源代码

解决方案 »

  1.   

    http://space.itpub.net/7311285/viewspace-97
      

  2.   

    静态化。生成HTML页面public static bool CreatHtmlPage(string[] strNewsHtml, string[] strOldHtml, string strModeFilePath, string strPageFilePath)
            {
                bool Flage = false;
                StreamReader ReaderFile = null;
                StreamWriter WrirteFile = null;
                //修改mode.htm到inc目录下
               strModeFilePath = "../inc/" + strModeFilePath;
                string FilePath = HttpContext.Current.Server.MapPath(strModeFilePath);
                Encoding Code = Encoding.GetEncoding("gb2312");
                string strFile = string.Empty;
                try
                {
                    ReaderFile = new StreamReader(FilePath, Code);
                    strFile = ReaderFile.ReadToEnd();            }
                catch (Exception ex)
                {
                    throw ex;
                }
                finally
                {
                    ReaderFile.Close();
                }
                try
                {
                    int intLengTh = strNewsHtml.Length;
                    for (int i = 0; i < intLengTh; i++)
                    {
                        strFile = strFile.Replace(strOldHtml[i], strNewsHtml[i]);
                    }
                    WrirteFile = new StreamWriter(HttpContext.Current.Server.MapPath(strPageFilePath), false, Code);
                    WrirteFile.Write(strFile);
                    Flage = true;
                }
                catch (Exception ex)
                {
                    throw ex;
                }
                finally
                {                WrirteFile.Flush();
                    WrirteFile.Close();
                }
                return Flage;
            }
            public static bool UpdateHtmlPage(string[] strNewsHtml, string[] strStartHtml, string[] strEndHtml, string strHtml)
            {
                bool Flage = false;
                StreamReader ReaderFile = null;
                StreamWriter WrirteFile = null;
                string FilePath = HttpContext.Current.Server.MapPath(strHtml);
                Encoding Code = Encoding.GetEncoding("gb2312");
                string strFile = string.Empty;
                try
                {
                    ReaderFile = new StreamReader(FilePath, Code);
                    strFile = ReaderFile.ReadToEnd();            }
                catch (Exception ex)
                {
                    throw ex;
                }
                finally
                {
                    ReaderFile.Close();
                }
                try
                {
                    int intLengTh = strNewsHtml.Length;
                    for (int i = 0; i < intLengTh; i++)
                    {
                        int intStart = strFile.IndexOf(strStartHtml[i]) + strStartHtml[i].Length;
                        int intEnd = strFile.IndexOf(strEndHtml[i]);
                        string strOldHtml = strFile.Substring(intStart, intEnd - intStart);
                        strFile = strFile.Replace(strOldHtml, strNewsHtml[i]);
                    }
                    WrirteFile = new StreamWriter(FilePath, false, Code);
                    WrirteFile.Write(strFile);
                    Flage = true;
                }
                catch (Exception ex)
                {
                    throw ex;
                }
                finally
                {                WrirteFile.Flush();
                    WrirteFile.Close();
                }
                return Flage;
            }
    生成静态页面的5种方案图片切割。生成缩略图
    /// <summary>
    /// 获取一个图片按等比例缩小后的大小。
    /// </summary>
    /// <param name="maxWidth">需要缩小到的宽度</param>
    /// <param name="maxHeight">需要缩小到的高度</param>
    /// <param name="imageOriginalWidth">图片的原始宽度</param>
    /// <param name="imageOriginalHeight">图片的原始高度</param>
    /// <returns>返回图片按等比例缩小后的实际大小</returns>
    public static Size GetNewSize(int maxWidth, int maxHeight, int imageOriginalWidth, int imageOriginalHeight)
    {
        double w = 0.0;
        double h = 0.0;
        double sw = Convert.ToDouble(imageOriginalWidth);
        double sh = Convert.ToDouble(imageOriginalHeight);
        double mw = Convert.ToDouble(maxWidth);
        double mh = Convert.ToDouble(maxHeight);    if (sw < mw && sh < mh)
        {
            w = sw;
            h = sh;
        }
        else if ((sw / sh) > (mw / mh))
        {
            w = maxWidth;
            h = (w * sh) / sw;
        }
        else
        {
            h = maxHeight;
            w = (h * sw) / sh;
        }    return new Size(Convert.ToInt32(w), Convert.ToInt32(h));
    }
    缓存都可以提高页面访问速度小技巧
      

  3.   

    要用ADO。NET不要用LIQN操作数据库
      

  4.   

    1.数据库优化,建立索引,使用视图、存储过程等。
    2.页面优化,用asp.net mvc  建立网站技术架构。
    3.建立页面缓存。
      

  5.   

    网站快于慢取决的因素很多
    带宽,服务器,数据库
    但相同条件下,数据库数据是重头,建议在数据查询,更新的时候做好优化工作,
    另外服务器也要比较牛B,负载也是可以考虑的.
    当然缓存也不错,比如用第三方的memcached工具来缓存更好
      

  6.   

    http://topic.csdn.net/u/20110321/23/b6c796ab-e11d-4d64-a078-5c2553e0f52a.html
      

  7.   

    生成html
    mvc
    关去没有用的视图
    缓存
      

  8.   

    太多了首先要考查目前网站的瓶颈在哪里,是访问数据库太慢?是生成页面时间太长?是在客户端呈现太慢?网站要在多个维度里表现的都足够快前端优化(请参考高性能网站建设指南、高性能网站建设进阶指南:Web开发者性能优化最佳实践)缓存(客户端、服务器端、数据库、分布式缓存)如果使用IIS,可能需要考虑IIS设置、URL优化ASP.NET中需要考虑哪些任务可以放到后台线程里数据库端的优化(请参考 SQL应用重构)还有和架构设计相关的,使用反向代理,CDN,如果进行负载均衡等等(请参考 构建高性能Web站点)
      

  9.   

    第一:生成html静态页面,第二:大批量数据,尽量使用分页,避免加载太大的图片,下来就是你自己代码规范了,
      

  10.   

    页面加载优化有很多方法:
    给LZ几个关键字,自己学习下吧。1、lazy lode延时加载
    2、缓存的多种方式:页面缓存、数据缓存等等
      

  11.   

    生成HTML页面+页面缓存  如果是大型民户的话!你参考http://space.itpub.net/7311285/viewspace-97
      

  12.   

    以上说的不少了,可以再次的google一下
      

  13.   

    我也很想知道。
    另外楼主 有兴趣的话 就看看缓存。
    asp,net 用缓存(页面,片段,数据库,cache)可以提高百分之20-80的性能