I have a website with a lot of static HTML pages. There are also some aspx pages in the site. We are using Forms Authentication with standard login controls and the default ASP.NET authentication provider to control user access. Only the aspx pages have their access or functionality controlled by who is logged in. The HTML pages are all open to the public.
However, we’d like to be able to show users who are logged in that they are logged in, even on the static HTML pages. We’ve got a link in the top right corner of the HTML pages to take the user to the login.aspx page. Is there any way to change this link, using jQuery or something similar so that users who are authenticated see their login name or even a link that logs them out? Ideally we’d like to show them their login name as a link that logs them out.
If this is possible, does anyone have an example of the code to do this that they can share?
It’s definitely possible, here’s an overview of the solution I’d use:
I’d use the jquery.ajax function to hit an asp.net generic handler (.ashx) page. There are plenty example of this on the web but as a quick example:
Then on the myServerSidePage.ashx I’d have a method along the lines of:
You’d obviously need some error checking around both the server side and ajax call as well.