2012-06-19 1 views
1

나는 Godaddy와 웹 호스트를 가지고 있으며 내 도메인으로 SSL 인증서를 가져 왔습니다. login.aspx 페이지와 register.aspx 페이지를 https로 이동시키는 간단한 방법이 있습니까? redirect ("https : //domain/login.aspx")라고 명시 적으로 말하고 싶지 않습니다. 어떤 도움을 주셔서 감사합니다.등록 및 로그인 페이지 사용 https asp.net 4.0

+0

아마도 수동 리디렉션이 가장 신뢰할 수있는 방법 일 것입니다. 왜 그게 너에게 어울리지 않는거야? –

답변

1

가장 쉬운 방법은 다음 코드로 페이지를 수정하는 것입니다. https로 리디렉션합니다.

if (!Request.IsLocal && !Request.IsSecureConnection) 
{ 
    string redirectUrl = Request.Url.ToString().Replace("http:", "https:"); 
    Response.Redirect(redirectUrl); 
} 
0

당신이 너트를 얻을 싶다면 종종 간단한 솔루션이 최고입니다,하지만 ... 당신은 확인 목록을 만들기 위해 HTTP 모듈을 쓸 수

: 보안 연결)를 로컬로 실행하지 아니하는 경우 특정 페이지가 SSL로 리디렉션됩니다.

public class EnsureSslModule : IHttpModule 
{ 
    private static readonly string[] _pagesToEnsure = new[] { "login.aspx", "register.aspx" }; 

    public void Dispose() 
    { 
    } 

    public void Init(HttpApplication context) 
    { 
     context.BeginRequest += OnBeginRequest; 
    } 

    public void OnBeginRequest(object sender, EventArgs e) 
    { 
     var application = (HttpApplication)sender; 
     var context = application.Context; 

     var url = context.Request.RawUrl; 

     if (!context.Request.IsSecureConnection 
       && _pagesToEnsure.Any(page => url.IndexOf(page, StringComparison.InvariantCultureIgnoreCase) > -1)) 
     { 
      var builder = new UriBuilder(url); 

      builder.Scheme = Uri.UriSchemeHttps; 

      context.Response.Redirect(builder.Uri 
       .GetComponents(UriComponents.AbsoluteUri & ~UriComponents.Port, 
           UriFormat.UriEscaped), true); 
     } 
    } 
}