473,668 Members | 2,377 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

WCF problem maintaining principal across service calls

M#
Hi everyone,

I'm using WCF authentication services in my current project. I used
the following information as a starting point:
http://msdn.microsoft.com/en-us/library/bb398990.aspx

Unfortunately, I can't manage to get/set the generic principal when I
call other services. The authentication cookie is always null. I've
included some of my Global.asax code below. Any help would be greatly
appreciated:

void Application_Sta rt(object sender, EventArgs e)
{
// Code that runs on application startup
AuthenticationS ervice.Authenti cating
+= new EventHandler<Au thenticatingEve ntArgs>
(Authentication Service_Authent icating);

/// Customize the cookie returned, adding role
/// and other information.
AuthenticationS ervice.Creating Cookie
+= new EventHandler<Cr eatingCookieEve ntArgs>
(Authentication Service_Creatin gCookie);
}

void AuthenticationS ervice_Authenti cating(object sender,
AuthenticatingE ventArgs e)
{
e.Authenticated = false;

/// Theoretical custom credential that would distinguish
/// duplicate user names for the purpose of ensuring
/// unique authentication MK 04/13/08
int organizationId;

string[] credentials = e.CustomCredent ial.Split(new char[]
{ ',' });

if (credentials.Le ngth != 0
&& int.TryParse(cr edentials[0], out organizationId) )
{
e.Authenticated =
MembershipManag er.ValidateUser (e.UserName,
e.Password,
organizationId) ;
}

e.Authenticatio nIsComplete = true;
}

void AuthenticationS ervice_Creating Cookie(object sender,
CreatingCookieE ventArgs e)
{
int organizationId;

if (int.TryParse(e .CustomCredenti al, out organizationId) )
{
string roles = RoleManager.Get RolesForUser(e. UserName,
organizationId) ;

FormsAuthentica tionTicket ticket = new
FormsAuthentica tionTicket(1,
e.UserName,
DateTime.Now,
DateTime.Now.Ad dHours(2),
false,
roles,
FormsAuthentica tion.FormsCooki ePath);

string encryptedTicket =
FormsAuthentica tion.Encrypt(ti cket);

HttpCookie cookie = new HttpCookie(
FormsAuthentica tion.FormsCooki eName,
encryptedTicket );

cookie.Expires = DateTime.Now.Ad dHours(2);
cookie.Domain = ".localhost ";
HttpContext.Cur rent.Response.C ookies.Add(cook ie);

e.CookieIsSet = true;
}
}

/// <summary
/// Recreates the Principal on every request, assigning roles
/// and other information from the authentication ticket.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
void Application_Aut henticateReques t(object sender, EventArgs e)
{
HttpCookie ticketCookie
=
Context.Request .Cookies[FormsAuthentica tion.FormsCooki eName];

if (null == ticketCookie)
{
return;
}

try
{
FormsAuthentica tionTicket ticket
= FormsAuthentica tion.Decrypt(ti cketCookie.Valu e);

if (null != ticket)
{
string[] roles =
RoleManager.Get RolesFromString (ticket.UserDat a);
FormsIdentity identity = new FormsIdentity(t icket);
Context.User = new GenericPrincipa l(identity, roles);
}
}
catch (Exception ex)
{
/// TODO: Make to call to exception utility method
}
}
Jun 1 '08 #1
0 1445

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1292
by: Leo Tohill | last post by:
In our IIS application we have C# "behind code" that calls across remoting to a service. In the service, we keep local storage on the thread. From instrumentation, I now realize that hundreds of threads are seen by the service. I'm quite sure that I never had that many simultaneous requests coming across remoting. IIS isn't running nearly that many threads. How are threads managed by remoting on the server side? I imagine they are...
0
1407
by: GnanaPrakash.R | last post by:
Hi All, I would like to trace all remoting calls happen from the client. I got a rough idea of creating custom service and injecting into the object/message chain. Now i want to pass the user information to the remote server, i used AppDomain.CurrentDomain.SetThreadPrincipal( Thread.CurrentPrincipal ); before making call from client, but in my interception logic i tried to read the user principal but no luck...iam getting null string. ...
0
920
by: Mythran | last post by:
We have a class that Implements IPrincipal (System.Security.Principal.IPrincipal). We have a business logic class library assembly that checks the Principal object for role information to see if the currently logged in user has access to specific roles... <snip> Public Class MyBusinessLogic Inherits ServicedComponent <AutoComplete()> _
0
1417
by: Mythran | last post by:
I have a custom Principal (implements System.Security.Principal.IPrincipal interface) that I need to access from a WebService. My web application has the Thread.CurrentPrincipal set to this new Principal object, as well as HttpContext.Current.User. But when I access either Thread.CurrentPrincipal or HttpContext.Current.User from the Web Service, they are not the same as those set in the Web Application (and I can see why). My question...
0
1082
by: google | last post by:
Hi, I use Custom Principal and it works well on my PC (Localhost). When I deploy it at my hosting service it fails. I print out HttpContext.Current.User.GetType().ToString() On my PC it is CustomPrincipal.
1
1247
by: giatorta | last post by:
Hi all, I have a scenario where the client calls Web Service WS1 and WS1 calls Web Service WS2 I have methods M1 on WS1 and M2 on WS2 both with EnabledSession=True assume M1 on WS1 does the following (in VB-like pseudocode): If (new session) Then Session("foo1") = "OLD1"
2
1613
by: ilyas | last post by:
Hi all I have a web service that I have written. It is written in C# I want to use this web service from a browser, but my users all have different browsers so its important that the code to access the web service works across IE, Firefox and other browsers Does anybody know if they are libraries out there that do this?
3
192
by: M# | last post by:
Hi everyone, I'm using WCF authentication services in my current project. I used the following information as a starting point: http://msdn.microsoft.com/en-us/library/bb398990.aspx Unfortunately, I can't manage to get/set the generic principal when I call other services. The authentication cookie is always null. I've included some of my Global.asax code below. Any help would be greatly appreciated:
3
1652
by: eschneider | last post by:
Just some common issues with WS: Using custom objects: When objects change, seems you are always fixing some issue. Update references, which sometimes does not work. Deployment: Weird errors which take a while to fix because the error stink: Forget to set ASP.NET 2.0="Parser Error Message: Could not load type" '*.Global' is ambiguous: it could come from assembly=I deleted the
0
832
mbmccormick
by: mbmccormick | last post by:
I have a web service in the same project as the rest of my website. I am able to call my web service without any trouble from the Javascript on my page using the Script Manager. Now, I want to have my web service access some of my business logic, and in order to do that I need to access the current Principal. The Principal object is set for the rest of the website, but not on my web service (where it uses WindowsIdentity instead of my...
0
8459
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8374
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8791
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8575
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8653
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5677
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4202
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4373
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2784
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.