Skip to content

Commit

Permalink
Merge branch 'master' of ssh://github.com/ServiceStack/ServiceStack
Browse files Browse the repository at this point in the history
  • Loading branch information
mythz committed Apr 14, 2014
2 parents 7364d4e + c8fceee commit 6cb92e0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 23 deletions.
20 changes: 6 additions & 14 deletions src/ServiceStack.Razor/ViewPageBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -530,21 +530,13 @@ public void ApplyRequestFilters(object requestDto)
public void RedirectIfNotAuthenticated(string redirectUrl=null)
{
if (IsAuthenticated) return;

if (redirectUrl != null)
{
Response.RedirectToUrl(redirectUrl);
}
else
{
var authFeature = AppHost.GetPlugin<AuthFeature>();
var virtualPath = authFeature != null && authFeature.HtmlRedirect != null
? authFeature.HtmlRedirect
: HostContext.Config.DefaultRedirectPath ?? HostContext.Config.WebHostUrl ?? "/";

var url = AppHost.ResolveAbsoluteUrl(virtualPath, base.Request);
Response.RedirectToUrl(url);
}
redirectUrl = redirectUrl
?? AuthenticateService.HtmlRedirect
?? HostContext.Config.DefaultRedirectPath
?? HostContext.Config.WebHostUrl
?? "/";
AuthenticateAttribute.DoHtmlRedirect(redirectUrl, Request, Response, includeRedirectParam: true);
throw new StopExecutionException();
}
}
Expand Down
22 changes: 13 additions & 9 deletions src/ServiceStack/AuthenticateAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,20 +88,24 @@ protected bool DoHtmlRedirectIfConfigured(IRequest req, IResponse res, bool incl
var htmlRedirect = this.HtmlRedirect ?? AuthenticateService.HtmlRedirect;
if (htmlRedirect != null && req.ResponseContentType.MatchesContentType(MimeTypes.Html))
{
var url = req.ResolveAbsoluteUrl(htmlRedirect);
if (includeRedirectParam)
{
var absoluteRequestPath = req.ResolveAbsoluteUrl("~" + req.PathInfo + ToQueryString(req.QueryString));
url = url.AddQueryParam(HostContext.ResolveLocalizedString(LocalizedStrings.Redirect), absoluteRequestPath);
}

res.RedirectToUrl(url);
DoHtmlRedirect(htmlRedirect, req, res, includeRedirectParam);
return true;
}

return false;
}

public static void DoHtmlRedirect(string redirectUrl, IRequest req, IResponse res, bool includeRedirectParam)
{
var url = req.ResolveAbsoluteUrl(redirectUrl);
if (includeRedirectParam)
{
var absoluteRequestPath = req.ResolveAbsoluteUrl("~" + req.PathInfo + ToQueryString(req.QueryString));
url = url.AddQueryParam(HostContext.ResolveLocalizedString(LocalizedStrings.Redirect), absoluteRequestPath);
}

res.RedirectToUrl(url);
}

public static void AuthenticateIfBasicAuth(IRequest req, IResponse res)
{
//Need to run SessionFeature filter since its not executed before this attribute (Priority -100)
Expand Down

0 comments on commit 6cb92e0

Please sign in to comment.