加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

ASP.NET重定向到默认重定向URL以外的页面

发布时间:2020-12-16 06:53:37 所属栏目:asp.Net 来源:网络整理
导读:在asp.net中,我们在使用表单身份验证时指定重定向URL,如下所示: authentication mode="Forms" forms name="myApp" loginUrl="Login.aspx" protection="All" defaultUrl="default.aspx" path="/" requireSSL="false"/ /authentication 这意味着当用户登录时,
在asp.net中,我们在使用表单身份验证时指定重定向URL,如下所示:

<authentication mode="Forms">
            <forms name="myApp" loginUrl="Login.aspx" protection="All" defaultUrl="default.aspx" path="/" requireSSL="false"/>
        </authentication>

这意味着当用户登录时,将被重定向到“default.aspx”
使用这种方法

FormsAuthentication.RedirectFromLoginPage(IDTextBox.Text,RememberCheckBox.Checked);

现在是否可以让用户在登录前选择要重定向到哪个页面?

例如,用户从列表中选择要在登录之前登录的页面,然后将经过身份验证的页面重定向到此页面而不是default.aspx页面.

这是可能的,如果是这样,怎么办呢?

解决方法

您可以使用 SetAuthCookie方法,然后手动重定向,而不是使用 RedirectFromLoginPage方法:

FormsAuthentication.SetAuthCookie(IDTextBox.Text,RememberCheckBox.Checked);
Response.Redirect("some url the user has choosen");

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读