本文整理汇总了C#中NancyContext.GetRedirect方法的典型用法代码示例。如果您正苦于以下问题:C# NancyContext.GetRedirect方法的具体用法?C# NancyContext.GetRedirect怎么用?C# NancyContext.GetRedirect使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NancyContext
的用法示例。
在下文中一共展示了NancyContext.GetRedirect方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: LogOutAndRedirectResponse
/// <summary>
/// Logs the user out and redirects them to a URL
/// </summary>
/// <param name="context">Current context</param>
/// <param name="redirectUrl">URL to redirect to</param>
/// <returns>Nancy response</returns>
public static Response LogOutAndRedirectResponse(NancyContext context, string redirectUrl)
{
var response = context.GetRedirect(redirectUrl);
var authenticationCookie = BuildLogoutCookie(currentConfiguration);
response.AddCookie(authenticationCookie);
return response;
}
示例2: UserLoggedInRedirectResponse
/// <summary>
/// Creates a response that sets the authentication cookie and redirects
/// the user back to where they came from.
/// </summary>
/// <param name="context">Current context</param>
/// <param name="userIdentifier">User identifier guid</param>
/// <param name="cookieExpiry">Optional expiry date for the cookie (for 'Remember me')</param>
/// <param name="fallbackRedirectUrl">Url to redirect to if none in the querystring</param>
/// <returns>Nancy response with redirect.</returns>
public static Response UserLoggedInRedirectResponse(NancyContext context, Guid userIdentifier, DateTime? cookieExpiry = null, string fallbackRedirectUrl = null)
{
var redirectUrl = fallbackRedirectUrl;
if (string.IsNullOrEmpty(redirectUrl))
{
redirectUrl = context.Request.Url.BasePath;
}
if (string.IsNullOrEmpty(redirectUrl))
{
redirectUrl = "/";
}
string redirectQuerystringKey = GetRedirectQuerystringKey(currentConfiguration);
if (context.Request.Query[redirectQuerystringKey].HasValue)
{
var queryUrl = (string)context.Request.Query[redirectQuerystringKey];
if (context.IsLocalUrl(queryUrl))
{
redirectUrl = queryUrl;
}
}
var response = context.GetRedirect(redirectUrl);
var authenticationCookie = BuildCookie(userIdentifier, cookieExpiry, currentConfiguration);
response.WithCookie(authenticationCookie);
return response;
}
示例3: UserLoggedInRedirectResponse
/// <summary>
/// Creates a response that sets the authentication cookie and redirects
/// the user back to where they came from.
/// </summary>
/// <param name="context">Current context</param>
/// <param name="userIdentifier">User identifier guid</param>
/// <param name="cookieExpiry">Optional expiry date for the cookie (for 'Remember me')</param>
/// <param name="fallbackRedirectUrl">Url to redirect to if none in the querystring</param>
/// <returns>Nancy response with redirect.</returns>
public static Response UserLoggedInRedirectResponse(NancyContext context, Guid userIdentifier, DateTime? cookieExpiry = null, string fallbackRedirectUrl = "/")
{
var redirectUrl = fallbackRedirectUrl;
string redirectQuerystringKey = GetRedirectQuerystringKey(currentConfiguration);
if (context.Request.Query[redirectQuerystringKey].HasValue)
{
redirectUrl = context.Request.Query[redirectQuerystringKey];
}
var response = context.GetRedirect(redirectUrl);
var authenticationCookie = BuildCookie(userIdentifier, cookieExpiry, currentConfiguration);
response.AddCookie(authenticationCookie);
return response;
}
示例4: LogOutAndRedirectResponse
/// <summary>
/// Logs the user out and redirects them to a URL
/// </summary>
/// <param name="context">Current context</param>
/// <param name="redirectUrl">URL to redirect to</param>
/// <returns>Nancy response</returns>
public static Response LogOutAndRedirectResponse(NancyContext context, string redirectUrl)
{
var response = context.GetRedirect(redirectUrl);
var authenticationCookie = BuildLogoutCookie(currentConfiguration);
response.WithCookie(authenticationCookie);
context.Items[UserLoggedOutKey] = new object();
context.CurrentUser = null;
if (context.Items.ContainsKey(AuthSessionIdItemKey))
{
currentConfiguration.AuthSessionIdStore.Remove((Guid)context.Items[AuthSessionIdItemKey]);
}
return response;
}
示例5: RedirectToFacebookLoginUrl
public static Response RedirectToFacebookLoginUrl(NancyContext context)
{
//TODO: The login parameters should be configurable
//TODO: Extract the redirect url (from the application authenticator) and pass it as a parameter
return context.GetRedirect(FacebookOAuthService.GetAbsoluteLoginUrl(Configuration.FacebookExtendedPermissions));
}
示例6: RedirectToFacebookLoginAndResetAuthenticationWhenNotAuthenticatedByFacebook
public static Response RedirectToFacebookLoginAndResetAuthenticationWhenNotAuthenticatedByFacebook(NancyContext context)
{
if (Enabled && !IsAuthenticatedByFacebook(context))
{
RemoveUserFromCache(context);
ApplicationAuthenticator.SetAsNotAuthenticated(context);
return context.GetRedirect(Configuration.FacebookLoginPath);
}
return context.Response;
}
示例7: LogoutFromFacebookAndRedirect
/// <summary>
/// Logs out the user from facebook and redirects to a given path (this will be normally the application logout path to complete the full logout)
/// </summary>
public static Response LogoutFromFacebookAndRedirect(NancyContext context, string path)
{
var facebookId = ApplicationAuthenticator.GetFacebookId(context);
if (facebookId.HasValue)
{
var accessToken = FacebookCurrentAuthenticatedUserCache.GetAccessToken(facebookId.Value);
return context.GetRedirect(FacebookOAuthService.GetFacebookLogoutUrl(path, accessToken));
}
return null;
}
示例8: LoginIntoApplicationWithFacebookOAthResponse
public static Response LoginIntoApplicationWithFacebookOAthResponse(NancyContext context, string pathToRedirectOnAutheticationFailure)
{
string code = context.Request.Query.code;
if (FacebookOAuthService.IsOAthResultSuccess(context))
{
var accessToken = FacebookOAuthService.GetAccessToken(code);
var me = FacebookClientService.GetFacebookMe(accessToken);
AddAuthenticatedUserToCache(me, accessToken);
var facebookId = Convert.ToInt64(me.id);
return LoginIntoTheApplicationAndRedirect(context, facebookId);
}
return context.GetRedirect(pathToRedirectOnAutheticationFailure);
}