帮忙看一下,为什么老报引用不存在应很简单

cqhydz 2004-11-03 04:55:36
页面中private void Gobutton_Click代码可以正常使用,但我单独放到一个.cs文件中老报引用不存在
页面后台代码
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace Webab
{
/// <summary>
/// WebForm 的摘要说明。
/// </summary>
public class WebForm : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label ListStr;
protected System.Web.UI.WebControls.TextBox TextBox1;
protected System.Web.UI.WebControls.Button Gobutton;
.
.
.

private void Gobutton_Click(object sender, System.EventArgs e)
{

if (! (Request.Cookies["Cookie1"] == null))
{

System.Collections.Specialized.NameValueCollection UserInfoCookieCollection = null;
UserInfoCookieCollection = Request.Cookies["Cookie1"].Values;
ListStr.Text = Server.HtmlEncode(UserInfoCookieCollection["Val1"]);



}

}

独立.cs类文件中

namespace Webab
{
/// <summary>
/// LoginClass 的摘要说明。
/// </summary>
public class LoginClass
{
public LoginClass()
{
//
// TODO: 在此处添加构造函数逻辑
//
public static string Login()
{
string loginbadge,tempname;
//此处代码是一样的
if (! (Request.Cookies["Cookie1"] == null))
{

System.Collections.Specialized.NameValueCollection UserInfoCookieCollection = null;
UserInfoCookieCollection = Request.Cookies["Cookie1"].Values;
ListStr.Text = Server.HtmlEncode(UserInfoCookieCollection["Val1"]);
return loginbadge;

}


}
...全文
75 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
brightheroes 2004-11-03
  • 打赏
  • 举报
回复
一样的
HttpContext.Current.Server.HtmlEncode(UserInfoCookieCollection["Val1"]);
cqhydz 2004-11-03
  • 打赏
  • 举报
回复
Server.HtmlEncode(UserInfoCookieCollection["Val1"]);
这句应如何修改啊
brightheroes 2004-11-03
  • 打赏
  • 举报
回复
在自己写的类里面,不能直接用Request,Reponse这些基于页面的对象
要通过HttpContext.Current来使用
cqhydz 2004-11-03
  • 打赏
  • 举报
回复
这是为什么
brightheroes 2004-11-03
  • 打赏
  • 举报
回复
try

Request.Cookies

--->

HttpContext.Current.Request.Cookies

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧