IIS 7 默认文件上传大小时30M
要突破这个限制:
1. 修改IIS的applicationhost.config
打开 %windir%\system32\inetsrv\config\applicationhost.config
找到: <requestFiltering>节点,
这个节点默认没有 <requestLimits maxAllowedContentLength="上传大小的值(单位:byte)" /> 元素,IIS 7和IIS 7.5上测试过 最大值只能是<requestLimits maxAllowedContentLength="4294967295" /> <4GB,
为这个节点新增如下事例元素:<requestLimits maxAllowedContentLength="2147483647" /> ,上传的大小将改为2G
注意: %windir%\system32\inetsrv\config\applicationhost.config 文件一定不要用其他机器的文件替换,否则IIS将无法启动
此文件记录了,当前IIS中所有Site , App pool的信息,还有一些与机器相关的配置。
2 修改web.config
<system.web>
<httpRuntime executionTimeout="36000" maxRequestLength="2097151"/> <!--maxRequestLength:上传的大小,单位K ,executionTime ......
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;
using System.Xml;
using System.Text;
using MSXML2;
namespace EC
{
/// <summary>
/// XML 操作基类
/// </summary>
public class XmlObject : IDisposable
{
//以下为单一功能的静态类
#region 读取XML到DataSet
/**************************************************
* 函数名称:GetXml(string XmlPath)
* 功能说明:读取XML到DataSet
* 参 数:XmlPath:xml文档路径
* 使用示列:
* using EC; //引用命名空间
* string xmlPath = Server.MapPath("/EBDnsConfig/DnsConfig.xml"); //获取xml路径
* DataSet ds = EC.XmlObject.GetXml(xmlPath); //读取xml到DataS ......
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;
using System.Xml;
using System.Text;
using MSXML2;
namespace EC
{
/// <summary>
/// XML 操作基类
/// </summary>
public class XmlObject : IDisposable
{
//以下为单一功能的静态类
#region 读取XML到DataSet
/**************************************************
* 函数名称:GetXml(string XmlPath)
* 功能说明:读取XML到DataSet
* 参 数:XmlPath:xml文档路径
* 使用示列:
* using EC; //引用命名空间
* string xmlPath = Server.MapPath("/EBDnsConfig/DnsConfig.xml"); //获取xml路径
* DataSet ds = EC.XmlObject.GetXml(xmlPath); //读取xml到DataS ......
谈谈ASP.NET中的“地址决定内容”问题
什么是地址决定内容?
你在网上逛,看到一个有趣的页面,于是你把地址栏里的内容复制下来,发给正在跟你聊天的网友:“看看这个页面,有趣极了”,你的朋友打开你发的链接,看到的内容应该和你正在看的一样。也即,页面的主要内容应当取决于地址栏中的地址。但在ASP.NET中,由于其独特的WebForm模型,可能会使得开发人员忽略了这重要的一点。
比如某在线小说网站的小说阅读界面是这样的:
页面分为二块,左块是目录列表,右块为正文,点击目录里的章节链接,右块里就显示对应章节的正文内容。
思路一:目录块和正文块都用GridView来做,GridView1绑定到目录表,用LinkButton显示章节标题,点击LinkButton后,在相关的事件处理函数里会查询对应的正文表,并绑定到GridView2上。
这个思路貌似OK,但是:无论你看的是哪一章节,地址栏里的地址都是不变的!这意味着,你无法把单独的一章的地址和别人分享,也不能把看到一半的章节添加到收藏夹里。在这个方案中,页面的主要内容——章节正文,与页面地址没有对应关系,所有章节都对应于同一地址。
改进:用url查询字符串标识章节,类似 ......
在2003系统下,按照在IIS6中网站右键属性-主目录-配置-在通配符应用程序映射-插入设置添加统配符,可执行文件选择C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll 注意“确认文件是否存在”这个选项不要选上
2 站点中引入UrlRewrting.dll
3 Web.config配置修改如下:
<RewriterConfig>
<RewriterRule>
<LookFor>~/article/</LookFor>
<SendTo>~/articlelist.aspx</SendTo>
</RewriterRule>
</RewriterConfig>
<httpModules>
<add name="MyHttpModule" type="UrlRewriting.MyHttpModule,UrlRewriting"/>
</httpModules>
<httpHandlers>
<add verb="*" type="UrlRewriting.Http404,UrlRewriting" path="404.aspx"/>
</httpHandlers>
4.效果测试:
http://www.xuehi.com/article/ ......
在2003系统下,按照在IIS6中网站右键属性-主目录-配置-在通配符应用程序映射-插入设置添加统配符,可执行文件选择C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll 注意“确认文件是否存在”这个选项不要选上
2 站点中引入UrlRewrting.dll
3 Web.config配置修改如下:
<RewriterConfig>
<RewriterRule>
<LookFor>~/article/</LookFor>
<SendTo>~/articlelist.aspx</SendTo>
</RewriterRule>
</RewriterConfig>
<httpModules>
<add name="MyHttpModule" type="UrlRewriting.MyHttpModule,UrlRewriting"/>
</httpModules>
<httpHandlers>
<add verb="*" type="UrlRewriting.Http404,UrlRewriting" path="404.aspx"/>
</httpHandlers>
4.效果测试:
http://www.xuehi.com/article/ ......
画面:
<asp:HiddenField ID="hfdXuHao" runat="server" />
<asp:TreeView ID="tvMenu" runat="server" CssClass="tvStyle" EnableClientScript="false"
OnSelectedNodeChanged="tvMenu_SelectedNodeChanged"
......
asp.net遍历HashTable需要用到DictionaryEntry Object,asp.net遍历HashTable,可以通过如下两种方法来实现,
方法一:
foreach (System.Collections.DictionaryEntry objDE in objHasTab)
{
Console.WriteLine(objDE.Key.ToString());
Console.WriteLine(objDE.Value.ToString());
}
方法二:
System.Collections.IDictionaryEnumerator enumerator = objHashTablet.GetEnumerator();
while (enumerator.MoveNext())
{
Console.WriteLine(enumerator.Key); // Hashtable关健字
Console.WriteLine(enumerator.Value); // Hashtable值
}
哈希表的简单操作
在哈希表中添加一个keyvalue键值对:HashtableObject.Add(key,value);
在哈希表中去除某个keyvalue键值对:HashtableObject.Remove(key);
从哈希表中移除所有元素: HashtableObject.Clear();
判断哈希表是否包含特定键key: Hashtab ......