Last post Aug 12, 2015 07:43 AM by deadtroll
Aug 10, 2015 10:33 AM|claudia888|LINK
I am working on a MVC3 web application that also has some web forms code in it, including the Login.aspx page. When user hit Login.aspx, they input their credentails, if authenticated, they will go to Default.aspx.
We had an issue with an user already logged in; but he opened a new tab, went to home page (index.html) there, then on this second window, he clicked "Log In" button again -
then he is shown the Login.aspx page, but without the Username and Password input fields.
What I want to achieve is: if the above scenario happens, he should see a friendly message, like "You have already logged in".
How do I achieve this with the page Login.aspx?
I'm thinking on Page.load, if not PostBack, check if the user has been authenticated; if yes, return with a message.
Is this the right way? Someone has a better suggestion?
Aug 10, 2015 11:41 AM|DeadTroll|LINK
There's a couple of ways you can do it, I would suggest using the control linked above. Login View Control which has two templates you can use. One for anonymous users and one for authenticated users. There is no code doing it this way just markup.
The other way is in the page load check if the user is logged in and programmatically set or switch around controls to be displayed to the user. I usually prefer to create 2 panels one for each type that I want to display in this case one for anonymous and
the other for authenticated users. Set them both to visible false and then in your code behind you can do a check something like this.
anonymousPanel.visible = user.isAuthenticated
authenticatedPanel.visible = user.isAuthenticated
This is of course for you web forms page, not your MVC page.
If you are having issues with your MVC page then you can do something like in the programmatic way I described above and use 2 partial views. Again 1 for anonymous and the other for authenticated.
Aug 11, 2015 09:48 PM|claudia888|LINK
Thanks a lot deadtroll!
This is exactly what I was looking for :-)
Aug 12, 2015 07:43 AM|DeadTroll|LINK