加载没有会话pagetype的页面时出错 [英] Error in loading the page without session pagetype

查看:78
本文介绍了加载没有会话pagetype的页面时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

if (Session["Pagetype"].ToString() == "EXIST" || !String.IsNullOrEmpty(qID) || Session["Pagetype"].ToString() == "Preview")







对象引用未设置为对象的实例两个会话都出错类型。






"Object reference not set to an instance of an object" error for both session type.

if (Session["Pagetype"].ToString() == "EXIST" || Session["Pagetype"].ToString() == "Preview")







FYI - 页面未加载会话页面类型。所以会话状态为false。




FYI - the page is not loading from the session page type. so the session state is false.

推荐答案

object pageType = Session["Pagetype"];
if ((!string.IsNullOrEmpty(pageType.ToString()) && 
    (pageType.ToString() == "EXIST" || pageType.ToString() == "Preview")))
     || !String.IsNullOrEmpty(qID) 





可能发生的事情是Session [Pagetype]返回null并且因此你不能采用null对象的.ToString()。你必须首先测试它为null



另一种写它的方式是





what is likely happening is that the Session["Pagetype"] is coming back null and as such you cannot take the .ToString() of a null object. you have to test it first for null

another way to write it is

object pageType = Session["Pagetype"];
if (!string.IsNullOrEmpty(pageType.ToString()))
{ 
    if (pageType.ToString() == "EXIST" || pageType.ToString() == "Preview"
     || !String.IsNullOrEmpty(qID)
    {
    }
}


这篇关于加载没有会话pagetype的页面时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆