getting the logged-in user identity in my custom app

This forum is only for questions or discussions about working with the mojoPortal source code in Visual Studio, obtaining the source code from the repository, developing custom features, etc. If your question is not along these lines this is not the right forum. Please try to post your question in the appropriate forum.

Please do not post questions about design, CSS, or skinning here. Use the Help With Skins Forum for those questions.

This forum is for discussing mojoPortal development

This forum is only for questions or discussions about working with the mojoPortal source code in Visual Studio, obtaining the source code from the repository, developing custom features, etc. If your question is not along these lines this is not the right forum. Please try to post your question in the appropriate forum.

You can monitor commits to the repository from this page. We also recommend developers to subscribe to email notifications in the developer forum as occasionally important things are announced.

Before posting questions here you might want to review the developer documentation.

Do not post questions about design, CSS, or skinning here. Use the Help With Skins Forum for those questions.
This thread is closed to new posts. You must sign in to post in the forums.
3/5/2010 8:17:02 AM
Gravatar
Total Posts 8

getting the logged-in user identity in my custom app

Hi,

 

I'm developing a custom web pages, I'm gonna display these pages in MojoPortal in a [iFrame], I want to get the logged-in username in my custom pages, to view specific info related to this logged-in user. what shall I do? and what code should I use in my custom web pages "Code-behind" to get the users name or e-mail.

 

Thanks in advance,

 

Andy

3/5/2010 2:52:41 PM
Gravatar
Total Posts 190

Re: getting the logged-in user identity in my custom app

using mojoPortal.Web;

SiteUser currentUser = SiteUtils.GetCurrentSiteUser();

Hope this helps.

John
 

3/6/2010 3:31:33 AM
Gravatar
Total Posts 8

Re: getting the logged-in user identity in my custom app

Thanks a lot, that really help, but I've a couple of questions about it, in order to use [using mojoPortal.Web;] I need to import the mojoPortal library "dll" in my project, right? how can I get it? BTW, I downloaded and I'm using the "Binary version" of MojoPortal, not the source-code one.

So the second question, can I use my current version of MojoPortal? or should I download and use the source-code one?

 

Thanks

 

Andy

3/6/2010 6:57:15 AM
Gravatar
Total Posts 18439

Re: getting the logged-in user identity in my custom app

Hi,

I'm working on a series of screen casts for developer training. I think you would benefit from watching them. 

http://www.mojoportal.com/developertrainingvideos.aspx

Hope it helps,

Joe

3/12/2010 1:46:36 PM
Gravatar
Total Posts 18439

Re: getting the logged-in user identity in my custom app

Also, if you don't need anything but the username or email you can just use

if(Request.IsAuthenticated)
string name = Context.User.Identity.Name;

if using email for login that will return the email address if not using email for login it returns the login name.

Hope it helps,

Joe

8/2/2011 10:59:41 AM
Gravatar
Total Posts 10

Re: getting the logged-in user identity in my custom app

Joe,

I have a custom ascx page with inline code.  I'm using both vbscript and javascript in the page.  How can I get the logged in user info passed to my page?  I saw your previous post about using this:

if(Request.IsAuthenticated)
string name = Context.User.Identity.Name;

where do I place this in my inline code?  Thank you for your help

 

 

8/2/2011 10:59:48 AM
Gravatar
Total Posts 10

Re: getting the logged-in user identity in my custom app

Joe,

I have a custom ascx page with inline code.  I'm using both vbscript and javascript in the page.  How can I get the logged in user info passed to my page?  I saw your previous post about using this:

if(Request.IsAuthenticated)
string name = Context.User.Identity.Name;

where do I place this in my inline code?  Thank you for your help

 

 

12/7/2012 11:14:31 AM
Gravatar
Total Posts 24

Re: getting the logged-in user identity in my custom app

Joe,

I was wondering how you can find out if someone is logged on from the client side.  The idea being that if a user is logged in then more content can be made visible using jquery.  

I was thinking of passing a value to an asp:hdden element when the user is logged in on page load.

Then I can use it to show/hide elements which provide more functionality.  Example: a calculator that allows non-members to use but if you are logged in then a save button is visible where you can save your results.

I am trying to do as much on the client side as possible and am making jquery Ajax calls to webmethods to save and load data.

Once a webmethod is called then it is easy to use 

 SiteUser CurrentUser = SiteUtils.GetCurrentSiteUser();

 OR 

Context.User.Identity.Name;

to see if a user is logged on and load or save info for that user.

Thoughts?

Thanks as always

 

12/7/2012 11:34:19 AM
Gravatar
Total Posts 18439

Re: getting the logged-in user identity in my custom app

Hi,

If you're already making calls to server side code with ajax why not just create your own method that you can call from ajax to check the user?

This thread on the asp.net forums may help.

Using hidden fields could also be done, but just be aware that client side things could be modified so any server side code that does things on behalf of the user should also do their own checks to validate that the user is authenticated.

Context.User.Identity.Name gets the user name from the authentication cookie which will either be the email or login name depending on which you are using to login. SiteUtils.GetCurrentSiteUser() is looking up the user based on Context.Identity.Name from the auth cookie, it returns null if the user is not authenticated.

Hope that helps,

Joe

12/10/2012 5:34:26 PM
Gravatar
Total Posts 24

Re: getting the logged-in user identity in my custom app

Of course,

That would be the easiest solution  here is what ended up working for me.  Thanks for the help.

client code:

 $.ajax({
                    url: "/Services/Page.aspx/uLog",
                    dataType: "json",
                    contentType: "application/json; charset=utf-8",
                    data: {},
                    type: "POST",
                    dataFilter: function(data) {
                      return data;
                    },
                    success: function(data) {
                      var Logged = data.d;
                        if (Logged == true)
                  {
                            //Do Something
                    },
                    error: function(XMLHttpRequest, textStatus, errorThrown) {
                      alert("Error getting LogON: " + textStatus);
                    }
                  });

Server Side:

[WebMethod]
        public static bool uLog()
        {
            bool ulog = false;
            SiteUser CurrentUser = SiteUtils.GetCurrentSiteUser();
            if (CurrentUser != null)
            {
                ulog = true;
            }
            else
            {
                ulog = false;
            }
            return ulog;
        }

 

12/11/2012 2:45:29 PM
Gravatar
Total Posts 18439

Re: getting the logged-in user identity in my custom app

Hi,

If you only need to know that the user is authenticated or not and don't need to check anything about the user or return any user properties you can simplify the code in your webmethod and remove the hit to the database that looks up the user, just:

return HttpContext.Current.Request.IsAuthenticated;

Best,

Joe

You must sign in to post in the forums. This thread is closed to new posts.