首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

为什么会出现“请求在此上下文中不可用”呢?该如何处理

2011-12-28 
为什么会出现“请求在此上下文中不可用”呢?我做了一个用户控件,此用户控件中只有一个控件(SiteMapPath)并将

为什么会出现“请求在此上下文中不可用”呢?
我做了一个用户控件,此用户控件中只有一个控件(SiteMapPath)
并将此用户控件放在母版页中,
在运行时出现如题的提示!
用户控件中的代码如下:

protected   void   Page_Load(object   sender,   EventArgs   e)
        {
                SiteMap.SiteMapResolve   +=   new   SiteMapResolveEventHandler(SiteMap_SiteMapResolve);
        }

        SiteMapNode   SiteMap_SiteMapResolve(object   sender,   SiteMapResolveEventArgs   e)
        {
                SiteMapNode   currentNode   =   SiteMap.CurrentNode.Clone(true);

                int   albumCategoryid;
                if   (Request.QueryString[ "cid "]   !=   null)
                {
                        albumCategoryid   =   Convert.ToInt32(Request.QueryString[ "cid "]);
                }
                else
                {
                        albumCategoryid   =   0;
                }

                if   (albumCategoryid   !=   0)
                {
                        currentNode.Url   =   currentNode.Url   +   "?cid= "   +   albumCategoryid.ToString();
                        currentNode.Title   =   "动态生成 ";
                }

                return   currentNode;
        }


提示说,Request.QueryString[ "cid "]这行有问题,不知为什么?
我现在想主要解决的问题是:
如何能够修改页面导航的地址及名称
我用的是SiteMapPath控件和web.sitemap
但是这不能满足我的要求,因为有些地址是动态,比如
www.hxling.com/album/albums.aspx?cid=1
www.hxling.com/album/albums.aspx?cid=1&aid=1
这样地址
在网上搜索了很多,看了天轰穿的动态修改内存中的地址,有点不好使!

我的站点地图文件如下:
<?xml   version= "1.0 "   encoding= "utf-8 "   ?>
<siteMap   xmlns= "http://schemas.microsoft.com/AspNet/SiteMap-File-1.0 "   >
    <siteMapNode   url= "~/default.aspx "   title= "首页 "     description= " ">
            <siteMapNode   url= "~/album/default.aspx "   title= "我的相册 "     description= "我的相册 "   >
                    <siteMapNode   url= "~/album/albums.aspx "   title= "相册类别 "   description= "相册类别 ">
                                <siteMapNode   url= "~/album/photos.aspx "   title= "相册名称 "   description= "相册名称 "> </siteMapNode>
                    </siteMapNode>


            </siteMapNode>
       
            <siteMapNode   url= "~/article/default.aspx "   title= "技术文章 "     description= "技术文章 "   />
            <siteMapNode   url= "~/login.aspx "   title= "用户登录 "     description= "用户登录 "   />
            <siteMapNode   url= "~/register.aspx "   title= "新用户注册 "     description= "新用户注册 "   />
            <siteMapNode   url= "~/error.aspx "   title= "系统提示 "     description= "系统提示 "   />
        </siteMapNode>
</siteMap>

希望各位能解答一下,为什么会出现如题的提示,或者能够解决我的问题,
其实我也想过不用ASP。NET2.0的站点导航,可以自己实现而且比较简单
即然微软出了这么个东东,我就想用这个实现!呵呵,学习学习,以后可以不用,但不可以不会用!

[解决办法]
在类文件里应用: Response 、 Request 、Session

要写全部路径

System.Web.HttpContext.Current.Response

System.Web.HttpContext.Current.Request

System.Web.HttpContext.Current.Session

[解决办法]
定个类级别int 变量,在page_load 里request得值赋给 int 变量,在sitemap方法里取int 变量进行解决
[解决办法]
参考一下微软PersonalWebSite实例网站
上面有类似的应用

热点排行