无法使用WindowsForms身份验证 [英] Not able to use WindowsForms Authentication
问题描述
我正在提供WCF服务,这是一种静态服务,因此没有维护会话,因为用户将使用Apple,Android和symbian等不同的移动平台,
但是问题是我想使用Windows窗体身份验证,我已经使用OAUTH实现身份验证,但是对于后续调用,我的客户希望我使用Windowsforms身份验证,并且他希望会话在12小时后关闭,因此我只是为此制作了一个POC(概念证明),但没有运行,
任何身体都能帮忙吗?
这是代码
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:
问候
Nakul Kundra
Regards
Nakul Kundra
推荐答案
告诉我们说无效数据"并没有给我们足够的信息来帮助您.您是否考虑过在调试器下运行它以查看问题所在?
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?
这篇关于无法使用WindowsForms身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!