Reputation: 1
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 e.g. 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.
Upvotes: 0
Views: 253
Reputation: 4268
Try this:
Response.Redirect(Server.MapPath("~/admin") + "login.aspx");
Upvotes: 1
Reputation: 2012
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!
Upvotes: 0
Reputation: 4866
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.
Upvotes: 0