我如何获得当前页面的名字,如果它不是在当页面是一个Web应用程序的默认页面的URL显示? [英] How do I get the current page name if it's not displayed in the URL when that page is the default page for a web app?

查看:151
本文介绍了我如何获得当前页面的名字,如果它不是在当页面是一个Web应用程序的默认页面的URL显示?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个ASP.NET网站。有一个在母版的ASP.NET菜单。我想隐藏菜单,如果当前页面的登录页面。我的登录页面为Login.aspx。这里的code如何使菜单可见/可见:

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();

但是,当我在IIS上部署它,网址不包括在网站上打开的第一次,因此菜单变得visible.How我决定在这种情况下,当前页的页面名称?

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?

推荐答案

您应该在服务器端做海事组织。反正假设你的web应用程序地址是 http://yourdomain.com/app/ 和登录页面的默认页。那么它会即使他不打字被displaied用户 http://yourdomain.com/app/login.aspx 所以我们需要检查的是,如果我们的地址与 yourdomain.com/app / 或没有结束。如果是这样,我们将隐藏菜单。

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 typing http://yourdomain.com/app/login.aspx so all we need to check is that if our address is ending with yourdomain.com/app/ or not. if so we will hide the menu.

var pathname = window.location.pathname;
var appDomainEndding = 'yourdomain.com/app/'
if (pathname.toLowerCase().indexOf("login.aspx") > -1 || 
    pathname.indexOf(appDomainEndding, pathname.length - appDomainEndding.length) > -1)
$('#mainmenu').hide();
else
$('#mainmenu').show();

这篇关于我如何获得当前页面的名字,如果它不是在当页面是一个Web应用程序的默认页面的URL显示?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆