且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何使用表单身份验证将用户重定向到特定页面

更新时间:2023-09-20 21:37:10

HI,probelm可能在IIS中,请查看以下链接以解决您的疑问。



http://www.aspdotnet-suresh.com/2011/05/requested-page-cannot-be-accessed.html [ ^ ]



无法访问请求的页面,因为页面的相关配置数据是无效。 [ ^ ]



c# - 无法访问请求的页面,因为页面的相关配置数据无效错误 - Stack Overflow [ ^ ]
probelm may be in IIS , please check these links below to solve your query.

http://www.aspdotnet-suresh.com/2011/05/requested-page-cannot-be-accessed.html[^]

The requested page cannot be accessed because the related configuration data for the page is invalid.[^]

c# - The requested page cannot be accessed because the related configuration data for the page is invalid error - Stack Overflow[^]


< authentication>部分配置应该在< system.web>内。部分







刚编辑完web.config:



The <authentication> part of the configuration should be inside the <system.web> section



Just edited the web.config:

<system.web>
   <authentication mode="Forms">
       <forms loginUrl="/Registration/LoginPage.aspx">
       </forms>
   </authentication>
   <compilation debug="true" targetframework="4.5.2" />
   <httpruntime targetframework="4.5.2" />
</system.web>


解决此问题的一种简单方法是在登录页面中使用身份验证过程在页面加载时检查来自AdminHome,学生,教师的页面中的身份验证详细信息。



在登录页面中验证成功后,将用户按角色重定向到相应的文件夹/页面。在重定向之前,在会话和cookie变量中保存所需的用户凭据。然后使用会话和cookie中的值,在上述文件夹中的相关页面上交叉检查用户。如果您使用母版页,则需要在母版页加载事件中仅检查一次所需的验证详细信息。如果用户详细信息不匹配,只需将用户重定向到登录页面或主页。



以下代码片段用于登录;



A simple way to solve this problem is using authentication process in login page and checking authentication details in pages from AdminHome, Student, Teacher at page load.

When authentication is successful in login page, redirect user as per role to corresponding folder/page. Before redirecting, save required user credentials in session and cookie variables. Then cross check user at related pages in above mentioned folder using this values from session and cookies. If you are using master page, then you need to check required authentication details only once in master page load event. If user details does not match, simply redirect user to either login page or home page.

Following code snippet is used for login;

Session["DynamicID"] = dynamic_id;
               Session["EmailID"] = txtbx_EmailID.Text.Trim();
               Session["DispName"] = GetDispName();

               app_cookie = new HttpCookie("App", dynamic_id);

               Response.AppendCookie(app_cookie);
               Response.RedirectPermanent("~/Dept/Default.aspx",true);





以下代码块用于母版加载事件;





Following code block is used at master page load event;

ses_autoid = Session["DynamicID"].ToString();
           cook_autoid = Request.Cookies.Get("App").Value.ToString();
           if (ses_autoid == cook_autoid)
           {
               Label_User.Text = "Display name: " + Session["DispName"].ToString();
               Label_User1.Text = Session["DispName"].ToString();
           }
           else {
               Response.RedirectPermanent("~/Common/LogOut.aspx", true);
           }