简体   繁体   中英

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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