Run custom code on login - asp.net

I’ve used the asp.net login control on my sharepoint custom master page. All works well and I can login to my site without problems.
However I’d like to run some code once the user has logged, or alternatively perform a redirect based on the user’s role.
Has anyone does this type of thing before?

The Login control (System.Web.UI.WebControls.Login) has an event LoggedIn (http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.login.loggedin.aspx). Just subscribe to it and place your code in the handler. I haven't worked with sharepoint, I'm talking from an ASP.NET viewpoint here.

You can test roles programmatically through User.IsInRole
EDIT: on redirect from the ASP.NET login control, check for the forms authenication token and run your custom code if the token is present.

Related

Automatically Sign In Sharepoint 2013

I want to sign in to a SharePoint portal through calling a web page. Forms based authentication is enabled on SharePoint.
The scenario is as follows:
Calling /_forms/default.aspx?username=userX. which is the default page for forms authentication in sharepoint.
The page create and set authentication ticket for userX without asking his password.
The page redirected to some default page.
I have tried to manipulated /_forms/default.aspx to create ticket using FederatedAuthentication.SessionAuthenticationModule.AuthenticateSessionSecurityToken,
but no result.
I'd greatly appreciated if some one helps me.

asp.net identity LoginView not switching to LoggedInTemplate

I have just started working on ASP.NET Identity. I created a web forms project in VS2013 using the Web Forms template.
Then I added BotDetect CAPTCHA in Register.aspx. I Registered the first user so that the Identity schema is created. so far so good.
Now, I observe a very strange thing - I start debugging my application - it shows me the home page. I click on "Log In" menu and the login page is shown. I enter the credential and click on Login. The user successfully logs-in (signinManager.PasswordSignIn returns SignInStatus.Success); however the LoginView does not switch to LoggedInTemplate.
Now, I just go to Register page and then go to Login page, then Login and this time the LoginView switches to LoggedInTemplate properly.
This has happened consistently - unless I go to the Register page the LoginView won't switch to LoggedInView.
Further, I commented the CAPTCHA code (but not the configuration done in the web.config). Now, even if I go to Register and then try to Login nothing happens (LoginView remains in AnonymousTemplate).
Is there any connection between LoginView and BotDetect CAPTCHA?
Please let me know if any more info is needed.
Thank you.
UPDATE:
I removed the BotCAPTCHA entirely from the project and now the LoginView correctly switches to LoggedInTemplate! My guess is that BotCAPTCHA does URL Rewriting and this is affecting it. I have posted this to BotCAPTCHA support and will Update here once they reply me.

ASP .NET Logout when url is modified or refreshed

hi i would like to know how would you lougout an user if he modifies the url or refreshes the web pages like in bank web sites
in asp .net.
Thanks for your answers
I have implemented a solution similar to Vignesh Kumar's answer by using roles and restricting access to pages based on the roles a user has. When a user logs in I check which pages they can access based on their assigned roles and build the navigation menu accordingly so that they're not able to navigate to restricted pages.
In my master page's Page_Load method I check whether a user has access to the page they're trying to access and if not I log them out and redirect them to the login screen.

Using Sessions in an ASP.NET 4.0 Log-In Control

I'm currently developing a website using Visual Studio 2010. As you all might know, creating a new website here automatically adds an Account folder which contains webpages like Login.aspx, etc. I am implementing this Login.aspx which contains the ASP.NET Login control. It's now functioning the way it should but I have a few concerns.
Before, I used to create my own UI for the log-in so managing sessions is not a problem to me. But since i'm currently using the Login.aspx which has a CS file almost empty, i don't have an idea where I can start implementing my session. Meaning to say, I don't know how to check programatically if the user has been successfully logged in so I can start implementing my session.
I would very much appreciate any pointer regarding this matter.
Thanks in advance. :)
You could subscribe for the Authenticate event and perform some custom authentication logic. Also you may take a look at the following article.
There are events associate with ASP.NET Login Control that you can use to create session like OnLoggingIn. Moreover you can find more about user validation from here Validating User Credentials Against the Membership

in asp.net login component doesn't redirect

Dear Experts,
I'm working with visual studio 2010
I’ve put a login component on my page, and defined users and roles in the asp.net web application administration
I don’t know why, but it’s not working, it’s not redirecting to the start page
It verifies the right and wrong passwords, and once it’s correct user name and password it doesn’t redirect… it just refresh the page and do nothing
Now, I thought I could debug step by step to know where it goes wrone, but since there is no code written , I don’t know where to put the breakpoint… that is my question
Please can you help me
.
If the login is succesful, to redirect the user to another page you should use the DestinationPageUrl property of the login control.

Resources