I have an ASP.NET web site. There's an ASP.NET menu on the Masterpage. I want to to hide the menu if the current page is the login page. My login page is Login.aspx. Here's the code how I make the menu invisible/visible:
var pathname = window.location.pathname;
if (pathname.toLowerCase().indexOf("login.aspx") > 0)
$('#mainmenu').hide();
else
$('#mainmenu').show();
But when I deploy it on the IIS, the url does not include the page name when the web site is opened for the first time, thus the menu becomes visible.How do I determine the current page in this case?
If you want to do that in javascript, you can do that as below
So,
Hope this will help you.
If the url doesn't change when on the login screen, your only options are to check the page's content, or to set a cookie: Make the server set something like a
"pageIsLogin=true"
cookie and check ifdocument.cookie
has that.(Don't forget to unset that cookie on other pages)
Or, like my fist suggestion, check if the page contains a login-specific element:
You should be doing it in server side IMO. anyway suppose your web app address is
http://yourdomain.com/app/
and your login page is the default page. then it will be displaied to user even if he is not typinghttp://yourdomain.com/app/login.aspx
so all we need to check is that if our address is ending withyourdomain.com/app/
or not. if so we will hide the menu.Supply a special variable on each "page". It's the classic go-to for this scenario. It is commonly used to allow a scripted, included menu system differentiate between any and all pages, and provide functionality on that basis such as highlighting, removing the link, etc. The way it works is to have a specific variable set on each page, which is then tested by the menu system and acted on accordingly.
The same variable can be reused for a variety of reasons, e.g. testing whether a specific function should be available, inclusion of page elements, etc.