[英]Redirecting to login page when user clicks a button
I want my anonymous user to be able to navigate throughout the website, but if he presses any button inside the site, he should be redirected to a login page. 我希望我的匿名用户能够在整个网站中导航,但如果他按下网站内的任何按钮,他应该被重定向到登录页面。 How do I achieve this? 我该如何实现这一目标?
Are there functions that I should use in the FormAuthentication class? 是否有我应该在FormAuthentication类中使用的函数?
Unfortunately, you need to write your own custom code for this (of course, you can use ASP.NET infrastructure). 不幸的是,您需要为此编写自己的自定义代码(当然,您可以使用ASP.NET基础结构)。 A general outline will be 概要将是
From better use experience, instead of doing post-back in #2, I will generate a java-script that will pop-up the login prompt (a modal dialog) if necessary and do the login via ajax call and then re-submit the form. 从更好的使用体验,我将生成一个java脚本,它将弹出登录提示(模式对话框),如果有必要,并通过ajax调用登录,然后重新提交形成。 Using library such as jquery, you can attach the necessary script-let to all submit buttons (or buttons marked with specific class) on the form. 使用诸如jquery之类的库,您可以在表单上附加必要的script-let到所有提交按钮(或标有特定类的按钮)。
You can set authentication in files by some setting in in web.config like. 您可以通过web.config中的某些设置来设置文件中的身份验证。
this will allow you to navigate all the pages. 这将允许您导航所有页面。 Now for any event in page like button click or something else you can write a function in which you can check authentication and authorization of user by Membership provider like 现在,对于页面中的任何事件,例如按钮单击或其他内容,您可以编写一个函数,您可以在其中检查成员资格提供程序的用户身份验证和授权
using System.Security.Authentication
Public void IsValidUser()
{
if(User.Identity.Name!=string.empty)
Response.Redirect("~login.aspx");
else
{
if(!User.Identity.IsAuthenticated)
Response.Redirect("~login.aspx");
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.