简体   繁体   English

Response.Redirect 问题

[英]Response.Redirect problam

I have a basic project with a menu bar that the server executes on each page.我有一个带有菜单栏的基本项目,服务器在每个页面上执行该菜单栏。 I want to prevent the access to the pages for unregistered users, so I added this code我想阻止未注册用户访问页面,所以我添加了这段代码

if (Session["username"] == null)
        Response.Redirect("HomePageWebSite.aspx");

When I load the HomePage by its self it works normaly, but when I use this code, the browser says that it can't find this page(unable to access this page).当我自己加载主页时,它可以正常工作,但是当我使用此代码时,浏览器说它找不到此页面(无法访问此页面)。 I checked the url of the homepage and it's the same one that the server can't access to.我检查了主页的网址,它与服务器无法访问的网址相同。 How can I solve this problem?我怎么解决这个问题?

If your home page is in the root change the code as below:如果您的主页在根目录中,请更改如下代码:

if (Session["username"] == null)
    Response.Redirect("/HomePageWebSite.aspx");

The "/" in the beginning will always lookup from the root directory.开头的“/”将始终从根目录查找。 If you do not give the "/" it will always lookup in the current directory which will results in problems if you have nested directories.如果您不提供“/”,它将始终在当前目录中查找,如果您有嵌套目录,这将导致问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM