Products

Solutions

Resources

Partners

Community

Blog

About

QA

Ideas Test

New Community Website

Ordinarily, you'd be at the right spot, but we've recently launched a brand new community website... For the community, by the community.

Yay... Take Me to the Community!

Welcome to the DNN Community Forums, your preferred source of online community support for all things related to DNN.
In order to participate you must be a registered DNNizen

HomeHomeDevelopment and...Development and...Getting StartedGetting StartedASP.NET AJAX Web Services - GetCurrentUserInfo.UserIDASP.NET AJAX Web Services - GetCurrentUserInfo.UserID
Previous
 
Next
New Post
1/9/2010 6:59 AM
 

I have added a web service (via VS2005 menu options) to my DNN5 website and I am calling a webmethod from javascript on another page in the project.  Everything works fine except in the webmethod,

GetCurrentUserInfo.UserID is returning -1 instead of the UserId of the currently logged-in user. Note that User.Identity.Name returns the correct UserName. Also, GetCurrentUserInfo.UserID returns correct value when the webmethod is called from the code-behind instead if the javascript.

 

I am considering using IWeb control in future but I am keen to sort this out for quick fix.

Ewan.

 
New Post
1/10/2010 11:24 PM
 

Hey Ewan,

The reason you're not getting a proper user id is because the code executing in your web method doesn't have any of the handy "current context" you'd normally have during a request. If you look at the source for that method you're calling, you'll see the first thing it does is check the current http context.

A quick fix for this would be to modify your web method to accept a user id or user name parameter and pass it in from the client side.

you could add something like this in your ascx

<script type="text/javascript">

var currentUserId = <% GetCurrentUserInfo.UserID %>;

</script>

And then when you make your ajax call, just use that JS variable.

Hope that helps,

Ian


Software Engineer
Co-Founder, dnnGallery
Stack Overflow: Ian Robinson
Twitter: @irobinson
Linked In: Ian Robinson
 
New Post
1/13/2010 4:53 AM
 

Thanks Ian.  Firstly, apologies for not replying earlier - I don't seem to get notifications that there has been a reply.  I have tried what you suggested and it works fine.  However, I have found I am able to evaluate User.Identity.Name in the webmethod which returns the login name, and from that get the ID from one of the applications business objects.  I prefer this slightly rather than exposing userid at the client (via view source).

Many thanks.

Ewan

 
New Post
1/20/2010 3:27 AM
 

Ian Robinson wrote:

A quick fix for this would be to modify your web method to accept a user id or user name parameter and pass it in from the client side.

you could add something like this in your ascx

And then when you make your ajax call, just use that JS variable.

Ian

 

This was the first thread, that I encountered when I googled out for this issue. I was doing it just for academic purposes. So, for those people who read this thread, I would like to mention that although Ian's approach works, IMHO it is not advisable to be followed at all. This opens the door to impersonation attempts where-in someone can try to pass userid manually using Http sniffers like fiddler, adn cause a whole lot of security concerns.

Although I use custom code for the resolution of this, IWeb in my opinion provides a comprehensive solution to the problem. If in hurry, you can use the other suggested approach for Identity, but I would rather never pass plain UserId/Username etc. fro js to a web-service.

 
Previous
 
Next
HomeHomeDevelopment and...Development and...Getting StartedGetting StartedASP.NET AJAX Web Services - GetCurrentUserInfo.UserIDASP.NET AJAX Web Services - GetCurrentUserInfo.UserID


These Forums are dedicated to discussion of DNN Platform and Evoq Solutions.

For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

  1. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DNN.
  2. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  3. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  4. No Flaming or Trolling.
  5. No Profanity, Racism, or Prejudice.
  6. Site Moderators have the final word on approving / removing a thread or post or comment.
  7. English language posting only, please.
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out