You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

C#中Response.Redirect针对MemberID=117出现虚拟路径无效错误排查

问题:MemberID=117时重定向出现单斜杠错误

场景与代码

我是C#新手,在页面http://admin.hcc.musc.edu/default.aspx中添加了后台脚本,意图根据QueryString中的MemberID值进行页面重定向:

<script runat="server">
protected override void OnLoad(EventArgs e)
{  
    // 获取MemberID的值
    string memberidvar = HttpContext.Current.Request.QueryString["MemberID"];

    // 针对MemberID=117的情况,要么退出函数要么重定向到主站
    if(memberidvar == "117")
    {
        // return; // 若需直接退出代码可启用此行
        // 重定向到主站
        Response.Redirect("https://researchers.hcc.musc.edu", true);
    }

    try
    {
        Response.Redirect("https://researchers.hcc.musc.edu?MemberID=" + Convert.ToString(memberidvar), true);
    }
    catch
    {
        // 重定向到错误页或输出错误信息
        Console.WriteLine("Wrong Direct");
    }
}
</script>

问题现象

目前除MemberID=117的情况外,其他数值均能正常工作,手动访问目标URL也无问题。IIS 6.1环境无额外重定向配置,但MemberID=117时出现如下错误:

[HttpException (0x80004005): 'https:/researchers.hcc.musc.edu/' is not a valid virtual path.]
System.Web.Util.UrlPath.CheckValidVirtualPath(String path) +11924876
System.Web.Util.UrlPath.Combine(String appPath, String basepath, String relative) +141
System.Web.VirtualPath.Combine(VirtualPath relativePath) +159
System.Web.HttpContext.RewritePath(String path, Boolean rebaseClientPath) +160
System.Web.UrlMappingsModule.UrlMappingRewritePath(HttpContext context) +180
System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +139
System.Web.HttpApplication.ExecuteStepImpl(IExecutionStep step) +195
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +88  

疑问

错误信息中的URL显示为https:/researchers.hcc.musc.edu/(仅单斜杠),想请教:

  • 是否需要使用特殊编码?
  • 为何仅MemberID=117会触发该问题?

内容的提问来源于stack exchange,提问作者Bill

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.10 06:48:26