c# - Why is the last part of this url not empty with ASP.NET webforms? -


why last part of url not empty? when visit website, default.aspx automaticly loads doesn't appear in url. use url highlight menu on website, doesn't work when first visit website.

this code how make menu-items:

string url = httpcontext.current.request.url.tostring();  // last part of url string path = url.split('/').last();  if (path == menupath || ((path == "default.aspx" && i==0) || (path == "" && i==0 )))     panel.controls.add(new literalcontrol("<a class='active' href='/" + menupath + "'>")); else     panel.controls.add(new literalcontrol("<a href='/" + menupath + "'>")); 

you think if url is: http://example.com/ path variable "" , should give class active right? right doesn't work , have no idea why.

make sure url lowercase if have issue! credits of suggestion go ron c

the problem httpcontext.current.request.url.absoluteuri contains full absolute url including protocol. if hover on in debugger see contains "http://example.com/default.aspx" when access example.com/ in browser.

you need update code accommodate or select different httpcontext.current.request.url property use. can inspect properties available hovering on var in debugger , expanding little triangle see it's properties.


Comments

Popular posts from this blog

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project.Error occurred in starting fork -

windows - Debug iNetMgr.exe unhandle exception System.Management.Automation.CmdletInvocationException -

configurationsection - activeMq-5.13.3 setup configurations for wildfly 10.0.0 -