首页 > 解决方案 > 主页上的 ASP.NET VB.NET 搜索按钮根据成员角色和当前目录更改目录

问题描述

使用 masterpage,我有一个输入和按钮,我需要能够在各个级别之间进行导航。我试过了

HttpContext.Current.Request.PhysicalApplicationPath 和其他几个 HttpContext 想法无法获取用户所在的当前文件夹目录。如何获取用户所在的当前目录?

例如,我需要知道用户是否在“level2”目录中,或者是否在“Level3”目录中,或者是否在根目录中。

myurl.com/default.aspx
myurl.com/Level2/default.aspx
myurl.com/level2/Level3/default.aspx

If user is in Level3 then
Redirect here..
ElseIf user is in Root directory Then
Redirect here..
ElseIf user is in Level2 directory Then
Redirect here..
End If

标签: asp.netvb.net

解决方案


类似于 VDWWD 所说的:

string[] levels = Request.Url.AbsolutePath.Split('/');

如果你Split()在斜线处('/'),你会得到 4 段

myurl.com/level2/Level3/default.aspx
     1      2      3         4

所以:

if(levels.Length == 4)
{
    // you're at level 3. the level is the always the length-1.
}

推荐阅读