简体   繁体   中英

how to redirect on a page in asp.net fom folder?

I have web project "myweb.com" .it contains a folder "admin". So I want when I open a link it should open a login page. For eg when I open link www.myweb.com/admin/ then it must be redirected on this link www.myweb.com/admin/login.aspx.kindly help me. I am new in web development.

尝试这个:

Response.Redirect(Server.MapPath("~/admin") + "login.aspx");

Check if user is authenticated then redirect if not....

    protected void Page_Load(object sender, EventArgs e)
    {
        if (HttpContext.Current.User.Identity.IsAuthenticated == false)
        {
            Response.Redirect("login.aspx");
        }
    }

If you don't specify a page then you need to do so in IIS otherwise you will get a 404 page not found error.

There are a few ways to do this. First way is using a link button then using the Repsonse.Redirect. Here it is shown below.

Code Behind

protected void lbLinkButton_Click(object sender, EventArgs e)
        {
            Response.Redirect("~/admin/login.aspx");
        }

ASP

<asp:LinkButton ID="lbLinkButton" runat="server" OnClick="lbLinkButton_Click">Login</asp:LinkButton>

Or you can just have the PostBackUrl in the ASP control as well... like so...

<asp:LinkButton ID="lbLinkButton" runat="server" PostBackUrl="~/admin/login.aspx">Login</asp:LinkButton>

Or you can use a Hyperlink like this..

<asp:HyperLink ID="hlHyperlink" runat="server" NavigateUrl="~/admin/login.aspx">Login</asp:HyperLink>

I hope this comes in handy!

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