1

Godaddyのウェブホストがあり、ドメインにSSL証明書を持ってきました。login.aspxページとregister.aspxページをhttpsに移動させる簡単な方法はありますか?明示的にredirect( "https://domain/login.aspx)と言う必要はありません。助けてくれてありがとう。

4

2 に答える 2

1

最も簡単な方法は、次のコードでこれらのページを変更することです(ローカルで実行されていない場合はhttpsにリダイレクトされ、安全な接続ではありません)。

if (!Request.IsLocal && !Request.IsSecureConnection)
{
    string redirectUrl = Request.Url.ToString().Replace("http:", "https:");
    Response.Redirect(redirectUrl);
}
于 2012-06-19T20:43:18.770 に答える
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);
        }
    }
}
于 2012-06-19T20:58:56.157 に答える