server.Transfer().............执行子请求错误 求教各位大虾啊~~~~

致知Fighting 致知Fighting 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
最近尝试用 ihttpHandler 实现请求拦截,验证权限,但是总是出错没有成功。

思路:请求————ihttpHandler(验证用户角色,并确定有没有权限访问要访问的页面)————验证成功在服务器转发请求到对应的页面


public void ProcessRequest(HttpContext context)
{
HttpSessionState session = context.Session;
HttpResponse response = context.Response;
HttpServerUtility server = context.Server;
HttpRequest request= context.Request;

if (session[CommonConstant.USER_NAME] == null)
{
response.Redirect("~/login.aspx");
}

String userName = session[CommonConstant.USER_NAME].ToString();
String userRole = session[CommonConstant.USER_ROLE].ToString();

if (!userRole.Equals(CommonConstant.STUDENT))
{
ExceptionReturnObject ero = new ExceptionReturnObject();
ero.ExceptionMsg = "您没有当前操作的权限,请联系管理员";
ero.ExceptionNum = CommonConstant.RIGHTEXCEPTION;
ExceptionHandler.exceptionHandler(ero, session, response);
}

server.Transfer(request.Path, true);
}


处理请求的代码如上,但是通过验证后的跳转代码总是在报错server.Transfer(request.Path, true);报执行子请求时错误

我在网上找了很多类似的问题,但是都没有解决。
context.Server.Transfer(BuildManager.CreateInstanceFromVirtualPath(context.Request.Path, typeof(Page)) as IHttpHandler, true);


用这个代码可以不报错,但是这样就会丢失请求数据,时受保护的页面都异常:连按钮都没有反应。

求教大虾们了~~~~怎么解决这个问题!!!!
...全文
评论 14
收藏 已收藏
分享
返回顶部
致知Fighting
C# 111,128 成员 642,536 内容