本文整理汇总了C#中HttpResult.SetCookie方法的典型用法代码示例。如果您正苦于以下问题:C# HttpResult.SetCookie方法的具体用法?C# HttpResult.SetCookie怎么用?C# HttpResult.SetCookie使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HttpResult
的用法示例。
在下文中一共展示了HttpResult.SetCookie方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Authenticate
public override object Authenticate(IServiceBase authService, IAuthSession session, Authenticate request)
{
var tokens = this.Init(authService, ref session, request);
var authServer = new AuthorizationServerDescription { AuthorizationEndpoint = new Uri(this.AuthorizeUrl), TokenEndpoint = new Uri(this.AccessTokenUrl) };
if (AuthServerFilter != null)
AuthServerFilter(authServer);
var authClient = new WebServerClient(authServer, this.ConsumerKey) {
ClientCredentialApplicator = ClientCredentialApplicator.PostParameter(this.ConsumerSecret),
AuthorizationTracker = new DotNetOpenAuthTokenManager(),
};
if (AuthClientFilter != null)
AuthClientFilter(authClient);
var authState = ProcessUserAuthorization(authClient, authServer, authService);
if (authState == null)
{
try
{
var authReq = authClient.PrepareRequestUserAuthorization(this.Scopes, new Uri(this.CallbackUrl));
var authContentType = authReq.Headers[HttpHeaders.ContentType];
var httpResult = new HttpResult(authReq.ResponseStream, authContentType) { StatusCode = authReq.Status, StatusDescription = "Moved Temporarily" };
foreach (string header in authReq.Headers)
{
httpResult.Headers[header] = authReq.Headers[header];
}
foreach (string name in authReq.Cookies)
{
var cookie = authReq.Cookies[name];
if (cookie != null)
{
httpResult.SetCookie(name, cookie.Value, cookie.Expires, cookie.Path, cookie.Secure, cookie.HttpOnly);
}
}
authService.SaveSession(session, this.SessionExpiry);
return httpResult;
}
catch (ProtocolException ex)
{
Log.Error("Failed to login to {0}".Fmt(this.Provider), ex);
return authService.Redirect(FailedRedirectUrlFilter(this, session.ReferrerUrl.SetParam("f", "Unknown")));
}
}
var accessToken = authState.AccessToken;
if (accessToken != null)
{
try
{
tokens.AccessToken = accessToken;
tokens.RefreshToken = authState.RefreshToken;
tokens.RefreshTokenExpiry = authState.AccessTokenExpirationUtc;
var authInfo = this.CreateAuthInfo(accessToken);
session.IsAuthenticated = true;
return OnAuthenticated(authService, session, tokens, authInfo)
?? authService.Redirect(SuccessRedirectUrlFilter(this, session.ReferrerUrl.SetParam("s", "1")));
}
catch (WebException we)
{
var statusCode = ((HttpWebResponse)we.Response).StatusCode;
if (statusCode == HttpStatusCode.BadRequest)
{
return authService.Redirect(FailedRedirectUrlFilter(this, session.ReferrerUrl.SetParam("f", "AccessTokenFailed")));
}
}
}
return authService.Redirect(FailedRedirectUrlFilter(this, session.ReferrerUrl.SetParam("f", "RequestTokenFailed")));
}