本文整理汇总了C#中Nancy.NancyContext.GetRedirect方法的典型用法代码示例。如果您正苦于以下问题:C# NancyContext.GetRedirect方法的具体用法?C# NancyContext.GetRedirect怎么用?C# NancyContext.GetRedirect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Nancy.NancyContext
的用法示例。
在下文中一共展示了NancyContext.GetRedirect方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: SetCurrentUserToViewBag
private Response SetCurrentUserToViewBag(NancyContext ctx)
{
var author = _viewProjectionFactory.Get<string, Author>(ctx.CurrentUser.UserName);
if (author == null)
return ctx.GetRedirect("/mz-login?returnUrl=" + Request.Url.Path).WithCookie(FormsAuthentication.CreateLogoutCookie());
ViewBag.CurrentUser = author;
return null;
}
示例3: SetContextUserFromAuthenticationCookie
private Response SetContextUserFromAuthenticationCookie(NancyContext ctx)
{
var username = FormsAuthentication.GetAuthUsernameFromCookie(ctx);
if (username.IsNullOrWhitespace())
return ctx.GetRedirect("/mz-login?returnUrl=" + Request.Url.Path).WithCookie(FormsAuthentication.CreateLogoutCookie());
ctx.CurrentUser = new BlogUserIdentity(username, new string[] {"admin" });
return null;
}
示例4: 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;
var response = context.GetRedirect(redirectUrl);
var authenticationCookie = BuildCookie(userIdentifier, cookieExpiry, currentConfiguration);
response.AddCookie(authenticationCookie);
return response;
}