在重定向"响应在此上下文中不可用"时获取错误

Dib*_*iya 13 c# asp.net session

我使用以下代码将用户重定向到页面.

Session["USERDATA"] = user;
if (roleName.Equals("Zerker", StringComparison.CurrentCulture))
   Response.Redirect("~/Account/Dashboard.aspx");
Run Code Online (Sandbox Code Playgroud)

但这会导致错误.

在这种情况下无法获得响应.

我该怎么办?

Mic*_* DN 36

我认为你在自己的班级中使用了响应对象.此对象将不可用.

尝试使用

HttpContext.Current.Response.Redirect("~/Account/Dashboard.aspx");
Run Code Online (Sandbox Code Playgroud)