Reputation: 10805
I am using asp.net membership, I have few pages at the root like loin, register, forget pass, that are accessible to all users before they log in or not registered, I want to stop these pages to accessible once user get logged in, I mean if a user manually type the URL in the Address Bar it allows to access those pages how to prevent this? Also, I am facing a problem how to redirect to a particulate page after getting logged in.
Upvotes: 0
Views: 121
Reputation: 15861
to redirect once Logged in check FormAuthentication.RedirectfromLoginPage
public void Login_OnClick(object sender, EventArgs args)
{
if (Membership.ValidateUser(UsernameTextbox.Text, PasswordTextbox.Text))
FormsAuthentication.RedirectFromLoginPage(UsernameTextbox.Text, NotPublicCheckBox.Checked);
else
Msg.Text = "Login failed. Please check your user name and password and try again.";
}
and you can check whether user is authenticated or not by
Page.User.Identity.IsAuthenticated
Check this links for forms authentications
Upvotes: 1
Reputation: 148120
You can use UrlReferrer to validate if page is accessed by navigation. UrlReferrer gets information about the URL of the client's previous request that linked to the current URL. for details visit this link
if(Request.UrlReferrer == null)
{
//code to redirection to login page
}
Upvotes: 1