本文介绍了有时会引发Null参考异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
<script language="javascript">
res = "&res="+screen.width+"x"+screen.height+"&d="+screen.colorDepth
top.location.href="Login.aspx?action=set"+res
</script>
源错误:
Source Error:
An unhandled exception was generated during the execution of the current web request,Information regarding origin and location exception can be identified using the exception stact trace below.
Stack trace:
[Null ReferenceException: object reference not set to an instance of an object.]
page_Load(object sender EventArgs e)+143
and next from System.Web
在Page_Load事件IAM的aspx.cs页面中检查
In aspx.cs page in Page_Load event iam checking for
if (Request.QueryString["action"] != null)
{
Session["ScreenResolution"] = Request.QueryString["res"].ToString();
}
然后也会出现Null ReferenceException异常.
Then also Null ReferenceException exception arises.
推荐答案
setTimeout(function() {
res = "&res="+screen.width+"x"+screen.height+"&d="+screen.colorDepth
top.location.href="Login.aspx?action=set"+res
}, 0);
这是必需的,因为脚本代码不能确定地执行.有时,它会在计算和填充屏幕尺寸之前运行.
在以下位置检查相同的情况:
http://stackoverflow.com/questions/7976369/null-reference-exception-is-有时会抛出 [ ^ ]
This is required because script code does not execute deterministically. Sometimes it will run before the screen dimensions have been calculated and populated.
check for the same scenario at:
http://stackoverflow.com/questions/7976369/null-reference-exception-is-thrown-sometimes[^]
这篇关于有时会引发Null参考异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!