0
누군가이 코드 조각의 무결성을 확인할 수 있습니까? 나는 URL을 https 및/또는 www로 정규화 할 수 있도록 컨트롤러를 꾸미고 싶습니다. ... 사전에ASP.NET MVC (2) NormalizeUrl 동작 필터 특성 (C#)
public class NormalizeUrl : ActionFilterAttribute {
private bool ForceHttps = false;
private bool ForceWww = false;
public NormalizeUrl() {
}
public NormalizeUrl(
bool ForceHttps,
bool ForceWww) {
this.ForceHttps = ForceHttps;
this.ForceWww = ForceWww;
}
public override void OnActionExecuting(
ActionExecutingContext Context) {
HttpRequestBase Request = Context.HttpContext.Request;
HttpResponseBase Response = Context.HttpContext.Response;
if (!Request.IsLocal) {
Uri Uri;
if (!Request.IsSecureConnection && ForceHttps) {
if (ForceWww) {
Uri = new Uri(Uri.UriSchemeHttps + "://www." + Request.Url.Host.Replace("www.", string.Empty) + "/" + Request.Url.AbsolutePath);
} else {
Uri = new Uri(Uri.UriSchemeHttps + "://" + Request.Url.Host.Replace("www.", string.Empty) + "/" + Request.Url.AbsolutePath);
};
} else if (!ForceHttps) {
if (ForceWww) {
Uri = new Uri(Uri.UriSchemeHttp + "://www." + Request.Url.Host.Replace("www.", string.Empty) + "/" + Request.Url.AbsolutePath);
} else {
Uri = Request.Url;
};
} else {
Uri = Request.Url;
};
Response.RedirectPermanent(Uri.AbsoluteUri, true);
};
}
}
감사합니다 첫 번째는 무한 리디렉션에 자신을 던져 때문에 코드의 내 두 번째 재 작성하지만, 어떻게 든 나는 아직도 꽤 없을 것 같아요!
당신이 보안 평가를 찾고 계십니까? –
아니요. 코드가 원하는대로 작동 할 경우 (http : // domain.com을 가져와 A) 'http : // domain.com'으로 바꾸고 자한다면 확인이나 개선 제안을 찾고 있습니다. /www.domain.com', B)'https : // domain.com' 또는 C)'https : // www.domain.com'을 입력하면됩니다. – Gup3rSuR4c