Click here to Skip to main content
15,909,039 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
hi,

I am making a WCF service which is a restful service, so there is not a session maintained, as the users will be different mobile platforms like Apple , Android and symbian,

but the problem is i want to make use of windows forms authentication, i have used an OAUTH implementation for authentication purpose, but for subsequent calls my client wants me to use windowsforms authentication, and he wants the session to be closed after 12 hours, so i just made a POC (Proof Of concept) for it but its not Running,

Can any body help


Here is the Code

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Security;
namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {
            Program user1 = new Program();
            string ticket = user1.MakeTicket();
            Console.WriteLine(ticket);
            Console.ReadKey();
            Console.WriteLine("Check the ticket");
            string ticketcheck = ticket;
            Console.WriteLine(user1.CheckTicket(ticketcheck).ToString());
            Console.ReadKey();
        }

        private string MakeTicket()
        {
            // Create a custom FormsAuthenticationTicket containing
            Boolean isPersistent = true;
            FormsAuthenticationTicket ticket = new FormsAuthenticationTicket("accesstoken", isPersistent, 1);
            // Encrypt the ticket and return
            return FormsAuthentication.Encrypt(ticket);

        }
        private Boolean CheckTicket(string TicketToCheck)
        {
            FormsAuthenticationTicket ticket = FormsAuthentication.Decrypt(TicketToCheck);  // here it gives an error saying invalid data

            if (ticket.Expired)
            {
                return false;
            }
            else
            {
                return true;
            }

        }
    }
}









AND GETTING THE FOLLOWING EXCEPTION


System.Web.HttpException was unhandled by user code<br />
Message=Unable to validate data.<br />
Source=System.Web<br />
ErrorCode=-2147467259<br />
WebEventCode=0<br />
StackTrace:<br />
at System.Web.Configuration.MachineKeySection.EncryptOrDecryptData(Boolean fEncrypt, Byte[] buf, Byte[] modifier, Int32 start, Int32 length, Boolean useValidationSymAlgo, Boolean useLegacyMode, IVType ivType, Boolean signData)<br />
at System.Web.Security.FormsAuthentication.Decrypt(String encryptedTicket)<br />
at WCFCustomAuthenticationTest.Service1.GetTicketExpiry(String Ticket) in c:\users\kundran\documents\visual studio 2010\Projects\WCFCustomAuthenticationTest\WCFCustomAuthenticationTest\Service1.svc.cs:line 46<br />
at SyncInvokeGetTicketExpiry(Object , Object[] , Object[] )<br />
at System.ServiceModel.Dispatcher.SyncMethodInvoker.Invoke(Object instance, Object[] inputs, Object[]& outputs)<br />
at System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc& rpc)<br />
InnerException:






Regards
Nakul Kundra
Posted
Updated 9-May-11 18:13pm
v2

1 solution

Telling us it says "invalid data" doesn't give us nearly enough info to help you. Have you considered running it under the debugger to see what's wrong?
 
Share this answer
 
Comments
nakulkundra 10-May-11 0:12am    
This is the Exception Details

System.Web.HttpException was unhandled by user code
Message=Unable to validate data.
Source=System.Web
ErrorCode=-2147467259
WebEventCode=0
StackTrace:
at System.Web.Configuration.MachineKeySection.EncryptOrDecryptData(Boolean fEncrypt, Byte[] buf, Byte[] modifier, Int32 start, Int32 length, Boolean useValidationSymAlgo, Boolean useLegacyMode, IVType ivType, Boolean signData)
at System.Web.Security.FormsAuthentication.Decrypt(String encryptedTicket)
at WCFCustomAuthenticationTest.Service1.GetTicketExpiry(String Ticket) in c:\users\kundran\documents\visual studio 2010\Projects\WCFCustomAuthenticationTest\WCFCustomAuthenticationTest\Service1.svc.cs:line 46
at SyncInvokeGetTicketExpiry(Object , Object[] , Object[] )
at System.ServiceModel.Dispatcher.SyncMethodInvoker.Invoke(Object instance, Object[] inputs, Object[]& outputs)
at System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc& rpc)
InnerException:

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900