ASP.NET VB.NET Search button on masterpage change directory depending on membership role and current directory

Using masterpage, I have an input and button I need to be able to do navigation between the levels. I’ve tried

HttpContext.Current.Request.PhysicalApplicationPath, and several other HttpContext ideas that do not work to get the current folder directory a user is in. How do I get the current directory a user is in?

For example, I need to know if user is in “level2” directory, or if in “Level3” directory, or if in root directory.

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

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

Similar to what VDWWD said:

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

If you Split() at the slash mark ('/'), you get 4 segments
myurl.com/level2/Level3/default.aspx
     1      2      3         4

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

Method 2

Using the code from the answer above:

Dim levels As String() = Request.Url.AbsolutePath.Split("/"c)
For Each value In Levels
   If value = "Field" Then
      Response.Redirect("~/Field/orders.aspx?OrderNo=" + qSearch.Text)
   ElseIf value = "Manage" Then
      Response.Redirect("~/Manage/orders.aspx?OrderNo=" + qSearch.Text)
   End If
Next


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x