フォーム認証を使用してWP7(マンゴー)エミュレータを使用して私の作品ウェブサイトにログオンしようとしています。Windows Phone 7.1(マンゴー)でのフォーム認証?
<system.web.extensions>
<scripting>
<webServices>
<authenticationService enabled="true" requireSSL="false"/>
</webServices>
</scripting>
彼らは基本的に認証ODataServiceを呼び出すことにより、ログインするサンプルコードがあります。これを含まWebConfigの
サイトは(最終的にあなたがこのサイトにいくつかのものを表示することができますWP7アプリを作成します)ユーザー/パスを渡し、認証Cookieを取得します。
このCookieを使用すると、すべての新しい要求がODataServiceに含まれ、データを取得できるはずです。
任意の要求が行われる前に - 認証Cookieを取得
private static string GetAuthenticationCookie(string username, string password)
{
if (authenticationCookie == null)
{
string loginServiceAddress = websiteUrl + "/Authentication_JSON_AppService.axd/Login";
var request = CreateAuthenticationRequest(username, password, loginServiceAddress);
var response = request.GetResponse();
if (response.Headers["Set-Cookie"] != null)
{
authenticationCookie = response.Headers["Set-Cookie"];
}
else
{
throw new SecurityException("Invalid credentials");
}
}
return authenticationCookie;
}
private static WebRequest CreateAuthenticationRequest(string username, string password, string loginServiceAddress)
{
var request = HttpWebRequest.Create(loginServiceAddress);
request.Method = "POST";
request.ContentType = "application/json";
var body = string.Format(
"{{ \"userName\": \"{0}\", \"password\": \"{1}\", \"createPersistentCookie\":false}}",
username,
password);
request.ContentLength = body.Length;
var stream = request.GetRequestStream();
using (var sw = new StreamWriter(stream))
{
sw.Write(body);
}
return request;
}
I CANTちょうどネットワークコードが若干異なっているとして、コピー&ペーストのWindows Phone 7.1(マンゴー)アプリにこのコードを - 例えば..everythingはWP7で非同期に行われ、もはや
myWebRequest.GetResponse()
のようなものworks..and私は
ような何かをしなければなりませんさmyWebRequest.BeginGetResponse()
誰でもWP7でフォーム認証を使用して認証を行う任意の作業コードサンプルがある場合 - 素晴らしいことだ
おかげで多くの
コードを使用することができません - コンパイルエラー - 一部のクラスが不足していますHttpUtilityExtensionsが原因です - – Jerrold
HttpUtilityExtensionsはここにあります:https://mytoolkit.svn.codeplex.com/ svn/Utilities/HttpUtilityExtensions.cs –
編集:https://mytoolkit.svn.codeplex.com/svn/Shared/Utilities/HttpUtilityExtensions.cs –