JOJ
踏踏实实做人,认认真真做事!放纵自己就是毁灭自己!

1Q .aspx页面在showmodeldialog情况下为什么一提交就重新打开一个页面?

  A:showmodaldialog打开的页面中在<head></head>之间加入一行:<base target="_self">

2Q:CS0246: The type or namespace name 'UserInfoModel' could not be found (are you missing a using directive or an assembly reference?)

A: 注意后台的namespace 和前台 的比较,有时侯我们复制页面时没有改命名空间

3Q: 关于ASP.NET页面中的Page_load执行两次的解决办法

A:  检测该页面上是有有 <img src="" /> 和引用到该页面的UserControl,master 页面上是否有<img src="" />这样的标签!  致于img标签为空执行page_load的原因是:img src=""   > img src="/"  > img src="/index.aspx",因为重新请求了index.aspx,所以page_load又执行了一次。不过如果IIS没有设置默认文档,该问题是不会出现的,所以一些人提及到本地调试没有问题,一旦上传至服务器就出问题,就是因为这个原因! 参考:http://blog.163.com/weeking_chen/blog/static/1305528892009108111318679/  防止page_load多次执行的办法最好是检查客户端是否有空src的图片,然后服务器端亦要做相关的安全检查,如果某个字段打算作为img src的值,一定要检查该值是否为空,不然....不幸又将降临你身上了。[这个问题太郁闷了]

4Q:无法加载文件或程序集'Revolution.WebSite11'或其依赖项之一。在位于集清单定义不匹配集的引用。 (从HRESULT异常:0x80131040)

   A:DLL程序集加载错误!把不必要的Dll删掉以免引用错误的DLL文件

5Q:会话状态才能使用时的EnableSessionState设置为true,无论是在配置文件或Page指令。请同时确保System.Web.SessionStateModule或自定义会话状态模块在<configuration> \的<system.web> \ <httpModules>区段包含在应用程序配置。

   A:在页面上加上<%@ Page Language="C#"  EnableSessionState="True" %>或者在web.config加上<pages enableSessionState="true" enableViewState="true" enableViewStateMac="true" validateRequest="false" >,建议加在web.config里面!因为这样不用每个页面加![如果在配置到sharepoint里面报这种错误,把sharepoint 端口下面的web.config 的<!--<pages enableSessionState="false" enableViewState="true" enableViewStateMac="true" validateRequest="false" pageParserFilterType="Microsoft.SharePoint.ApplicationRuntime.SPPageParserFilter, Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" asyncTimeout="7">-->
改为:<pages enableSessionState="true" enableViewState="true" enableViewStateMac="true" validateRequest="false">]

6Q:  w3wp.exe - application Error,Application has generated an exception that could not be handled. Process ID=0xfdc(4060),Thread ID=0x8ac(2220). Click Ok to terminate the application.  Click Cancel to debug the application.

w3wp.exe是IIS的一个进程!发生这个错误他会关掉IIS,如果再次访问页面就会报 503 错误!这个错误可能由代码引发!JS代码或后台代码!最初我遇到这个问题的时候还以为是电脑服务出现了问题!害的我每次只有重新启动电脑才能运行!后来知道是IIS服务关闭了!直接打开IIS就可以了!代码也做相应的更改就可以了!

7Q :Unable to serialize the session state. In 'StateServer' and 'SQL Server' mode, ASP.NET will serialize the session state objects, and as a result non-serializable objects or MarshalByRef objects are not permitted. The same restriction applies if similar serialization is done by the custom session state store in 'Custom' mode.

    A:被使用的类必须标记为可序列化!

在ASP.NET中使用AJAX那点事!

8Q:Fileupload 不能放在 uploadpanl 里面!

A:如果你那样做了,FileUpload1.HasFile一直为false;

解决方案:http://www.cnblogs.com/jinho/archive/2010/04/05/1704744.html

9Q: Microsoft JScript 运行时错误: Sys.WebForms.PageRequestManagerParserErrorException: 无法分析从服务器收到的消息。之所以出现此错误,常见的原因是: 在通过调用 Response.Write() 修改响应时,将启用响应筛选器、HttpModule 或服务器跟踪。详细信息: 分析附近的“ASP.testbutton_aspx4”时出错。

A:  使用了uploadpanl 后,不能使用Response.Write(“str”)了,检测你代码中哪里使用了Response.Write(“”);

解决方案:http://www.cnblogs.com/jinho/archive/2010/04/05/1704744.html

10Q: Foreach Collection was modified; enumeration operation may not execute."的错误。

你在Foreach里面更改了Foreach里面元素的内容,如果你只修改一个,请修改后执行break;

如果需要循环修改,则用For

11Q. Validation of viewstate MAC failed. If this application is hosted by a Web Farm or cluster, ensure that <machineKey> configuration specifies the same validationKey and validation algorithm. AutoGenerate cannot be used in a cluster.

在aspx页面增加

<%@ Page Language="C#" enableViewStateMac="false" %>

解决方案(2)推荐

<machineKey validationKey="B8CEF0C74E23E7197FCC4C9E3617C0007D94D43C7F7A79C582C54B95D69B946DFD49CAF5AA72F9A8CA2CBA040A9DF64DC1DF90DAE1214AE4F1AB7FA56DD65C0D" decryptionKey="D7F1CE31847C4FB31EF51E14F3820D52B659AF8523FC932C03506CC075DB8B28" validation="SHA1" decryption="AES" />

12Q. Exception of type 'System.OutOfMemoryException' was thrown.

at System.IO.MemoryStream.set_Capacity(Int32 value)
  at System.IO.MemoryStream.EnsureCapacity(Int32 value)
  at System.IO.MemoryStream.WriteByte(Byte value)
  at System.IO.BinaryWriter.Write(Byte value)
  at System.Runtime.Serialization.Formatters.Binary.ObjectNull.Write(__BinaryWriter sout)
  at System.Runtime.Serialization.Formatters.Binary.__BinaryWriter.WriteNullMember(NameInfo memberNameInfo, NameInfo typeNameInfo)
  at System.Runtime.Serialization.Formatters.Binary.ObjectWriter.CheckForNull(WriteObjectInfo objectInfo, NameInfo memberNameInfo, NameInfo typeNameInfo, Object data)
  at System.Runtime.Serialization.Formatters.Binary.ObjectWriter.WriteMembers(NameInfo memberNameInfo, NameInfo memberTypeNameInfo, Object memberData, WriteObjectInfo objectInfo, NameInfo typeNameInfo, WriteObjectInfo memberObjectInfo)
  at System.Runtime.Serialization.Formatters.Binary.ObjectWriter.WriteMemberSetup(WriteObjectInfo objectInfo, NameInfo memberNameInfo, NameInfo typeNameInfo, String memberName, Type memberType, Object memberData, WriteObjectInfo memberObjectInfo)
  at System.Runtime.Serialization.Formatters.Binary.ObjectWriter.Write(WriteObjectInfo objectInfo, NameInfo memberNameInfo, NameInfo typeNameInfo, String[] memberNames, Type[] memberTypes, Object[] memberData, WriteObjectInfo[] memberObjectInfos)
  at System.Runtime.Serialization.Formatters.Binary.ObjectWriter.Write(WriteObjectInfo objectInfo, NameInfo memberNameInfo, NameInfo typeNameInfo)
  at System.Runtime.Serialization.Formatters.Binary.ObjectWriter.Serialize(Object graph, Header[] inHeaders, __BinaryWriter serWriter, Boolean fCheck)
  at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize(Stream serializationStream, Object graph, Header[] headers, Boolean fCheck)
  at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize(Stream serializationStream, Object graph)
  at System.Web.UI.ObjectStateFormatter.SerializeValue(SerializerBinaryWriter writer, Object value)

这个问题郁闷了一天!不过还要找到问题的症状了!因为这个vs调试他又不报错,断点也一切正常!偏偏是断点跑完了,page_load也跑完了,过一会他就来这个错误了!首先看下面的错误堆栈信息。System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize 说明问题出现在序列化与反序列化这里! 我当初怎么也没有想到这里这里[主要原因没有看堆栈信息啊],而且报错的地方都不是我调用的方法

我程序里面有下面代码:

/// <summary>
        /// 将对象序列化为Byte[]数组类型,数据库里面对应的字段为:varbinary类型
        /// </summary>
        /// <param name="obj">obj</param>
        /// <returns></returns>
        public static byte[] ToByteArr(Object obj)
        {
            using (MemoryStream ms = new MemoryStream())
            {
                BinaryFormatter bf = new BinaryFormatter();
                if (obj == null) return null;
                bf.Serialize(ms, obj);
                byte[] byteArr = ms.ToArray();
                return byteArr;
            }
        }
        /// <summary>
        /// 将Byte[]数组反序列化为一个对象
        /// </summary>
        /// <typeparam name="T">T</typeparam>
        /// <param name="bytes">bytes</param>
        /// <returns></returns>
        public static T ToObj<T>(byte[] bytes)
        {
            if (bytes == null) { return default(T); }
            using (MemoryStream ms = new MemoryStream(bytes))
            {
                BinaryFormatter bf = new BinaryFormatter();
                Object obj = bf.Deserialize(ms);
                return (T)obj;
            }
        }
之前由于:MemoryStream 没有释放资源,if (bytes == null) { return default(T); } 且这个没有判断!
如果报OutOfMemoryException[内存溢出]错误,请检查 sql 的时候是否及时关闭了资源,还有I/O 操作,流操作 等等!
 13Q:String was not recognized as a valid DateTime.[字符串不是有效的时间格式]
1.Convert.ToDateTime("28-4-2010").ToString("d-M-yyyy")); [如果把 日-月-年 格式用于转换则报错]
2.DateTime dt = DateTime.ParseExact("28-4-2010", "d-M-yyyy", null);
3.DateTime mydt = DateTime.Now.ToLocalTime();
  DateTime.TryParse("28-04-2010", out mydt); [返回bool类型,自动带有try catch]
 14Q:Mailbox unavailable. The server response was: 5.7.1 Unable to relay for myname#mycompany.com [发送邮件出错]
原因:
<system.net>
        <mailSettings>
            <smtp>
                <network host="youhostname.domin.com"/>
            </smtp>
        </mailSettings>
    </system.net>
smtp出现了问题!下面方法来源于网络,我没有测试过!
  1. 打开 IIS 管理界面,先点击 控制面板 –> 管理工具 再选 IIS。
  2. 打开 Default SMTP Virtual Server 然后右击 Domains –> 新建 –> Domain…
  3. 在新建的屏幕上,选 Remote - 远程域名.
  4. 下一屏,填写你准备发送电邮的域名,如上面我代码的例子,我会填上 mycompany.com 然后点 Finish - 完成。
  5. 退出新建后,选中刚建的那个域名,右击打开 Proprieties - 属性 窗口
  6. 选中第一个复选框 Allow incoming mail to be relayed to this domain。
  7.  

你也可以通过你的本地机连接你的公司邮件服务器来转发公司内部或外部的信件,具体做法是将你公司的邮件服务器的IP地址或服务器名输入到上图的转发服务器(Forward all mail to smart host)的文本框内。

切记,输入 IP 地址时,记住用方括号符号来围住 IP address;象这样 [192.168.2.1] 。

另外一些设置改动:

1) 新加域名时,可以用星号表示所有的带有.com的域名 “*.com”
2) 如下图一样,将公司邮件服务器作为本地机的 Smart host 来转发一些本地机不能发送的一些电邮。

15Q:TemplateField 上不支持回调,因为某些控件不能在回调中正确更新。关闭“GridView1”上的回调。

在gridview中设置了 AllowPaging为true后,EnableSortingAndPagingCallbacks设为True后会出现如下错误:TemplateField 上不支持回调,因为某些控件不能在回调中正确更新。关闭“GridView1”上的回调。

因此如果在 GridView中想使用TemplateField的话EnableSortingAndPagingCallbacks必须设为False,否则把TemplateField删掉

16Q:在建立与服务器的连接时出错。在连接到 SQL Server 2005 时,在默认的设置下 SQL Server 不允许进行远程连接可能会导致此失败。 (provider: 命名管道提供程序, error: 40 - 无法打开到 SQL Server 的连接)

你可能连接的数据库是SQL Server 2005 Express Edition,从"开始菜单"调出"配置工具"中的"SQL Server 外围应用配置器".然后单击"服务和连接外围应用配置器",选择数据库实例(默认是"SQLEXPRESS",选择database Engine的"远程连接"中的"本地连接和远程连接(用TCP/IP)",这样即可打开SQL Server 2005的远程连接(默认不允许).
其实你可以
配置文件:
<connectionStrings>
<add name="testDBConnectionString" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=D:\wwwroot\sszTest1\App_Data\testDB.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True" providerName="System.Data.SqlClient"/>
</connectionStrings>
程序调用时:
SqlConnection sqlCon = new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["testDBConnectionString"].ToString());//testDBConnectionString
或都直接生成connection:
SqlConnection sqlCon = new SqlConnection("Data Source=.\\SQLEXPRESS;AttachDbFilename=D:\\wwwroot\\sszTest1\\App_Data\\testDB.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True")
只要连接成功,你再生成DataSource应该不成问题.

 

17Q:在建立与服务器的连接时出错。在连接到 SQL Server 2005 时,在默认的设置下 SQL Server 不允许进行远程连接可能会导致此失败。 (provider: SQL 网络接口, error: 26 - 定位指定的服务器/实例时出错)

首选请确认SQL SERVER EXPRSS已安装到本地计算机上,并且SQL SERVER (SQLEXPRESS)服务已经成功启动。如果问题仍然存在,可以尝试应打开“SQL Server 外围应用配置器”,选择“服务和连接的外围应用配置器”,然后将“远程连接”配置为“同时使用 TCP/IP 和 named pipes”

18Q:由于启动用户实例的进程时出错,导致无法生成 SQL Server 的用户实例。该连接将关闭。

将连接字符串中的“User Instance=True”修改为“User Instance=False”即可。
相关参考文章请参阅
《非管理员用户实例》

19Q:无法将文件 'X:\Website\App_Data\Database.mdf' 作为数据库 ''. 附加。当前命令发生了严重错误。应放弃任何可能产生的结果。

需要为X分区以及X分区的子文件夹和文件分配Users组的“读取”权限。

20Q:尝试为文件 X:\Website\App_Data\Database.mdf 附加自动命名的数据库,但失败。已存在同名的数据库,或指定的文件无法打开或位于 UNC 共享目录中。

首选要确认已经为X分区以及X分区的子文件夹和文件分配了Users组的“读取”权限。如果问题仍然存在,请使用SQL Server Management Studio连接到SQLEXPRESS数据库实例,检查是否有名称是“Database”的数据库存在。如果有,分离同名数据库即可。

21Q:无法打开用户默认数据库。登录失败。用户 'NT AUTHORITY\NETWORK SERVICE' 登录失败。

数据库文件Database.mdf 的读写权限被设置成只有NETWORK SERVICE才具有。解决方法是先停止掉SQL SERVER (SQLEXPRESS)服务,然后从父项集成权限,再次启动SQL SERVER (SQLEXPRESS)服务即可。

22Q:Validation of viewstate MAC failed. If this application is hosted by a Web Farm or cluster, ensure that <machineKey> configuration specifies the same validationKey and validation algorithm. AutoGenerate cannot be used in a cluster[验证的视图状态验证失败。如果这个申请是由Web场或群集,主办确保配置指定的<machineKey>相同的validationKey和验证算法。不能使用自动生成在群集]

1.处理页面增加<%@ Page Language="C#" enableViewStateMac="false" %>

2.推荐:<machineKey validationKey="B8CEF0C74E23E7197FCC4C9E3617C0007D94D43C7F7A79C582C54B95D69B946DFD49CAF5AA72F9A8CA2CBA040A9DF64DC1DF90DAE1214AE4F1AB7FA56DD65C0D" decryptionKey="D7F1CE31847C4FB31EF51E14F3820D52B659AF8523FC932C03506CC075DB8B28" validation="SHA1" decryption="AES" />

23Q:SQLServer2008附加Northwind和Pub数据报:SQL Server Upgrade 2000 - 2005 files read only but not really,Error:3415
 

  最初我用Windows登录SQL出现了这个错误,后来改为Sa登录问题解决

 

Technorati 标签: asp.net Error

 

 

 

 

 

 

posted on 2010-04-03 18:12  JoinJ  阅读(2179)  评论(0编辑  收藏  举报