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?
Unfortunately, you need to write your own custom code for this (of course, you can use ASP.NET infrastructure). 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. 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.
You can set authentication in files by some setting in in web.config like.
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");
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.