[英]how to redirect on a page in asp.net fom folder?
I have web project "myweb.com" .it contains a folder "admin". 我有一个Web项目“ myweb.com”。它包含一个文件夹“ 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. 例如,当我打开链接www.myweb.com/admin/时,必须在此链接上将其重定向www.myweb.com/admin/login.aspx.kindly帮助我。 I am new in web development. 我是Web开发的新手。
尝试这个:
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. 如果未指定页面,则需要在IIS中指定页面,否则将收到404页面未找到错误。
There are a few ways to do this. 有几种方法可以做到这一点。 First way is using a link button then using the Repsonse.Redirect. 第一种方法是使用链接按钮,然后使用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控件中也有PostBackUrl ...就像这样...
<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! 我希望这会派上用场!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.