How to Enforce HTTPS For ASMX Service

╄→гoц情女王★ 提交于 2019-12-05 13:49:44

Have you tried with URL rewrite?

<rewrite>
    <rules>
        <rule name="Force HTTPS" stopProcessing="true">
            <match url="(.*)/ServiceName.asmx" />
            <conditions>
                <add input="{HTTPS}" pattern="^OFF$" />
            </conditions>
            <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="Permanent" />
        </rule>
    </rules>
</rewrite>

A simpler solution would be just to include the following code in the constructor of each service - allowing you to decide it on each service individually.

if (!HttpContext.Current.Request.IsSecureConnection)
{
    var sslUrl = HttpContext.Current.Request.RawUrl.Replace("http://", "https://");

    Response.Clear();
    Response.Write(string.Format("This service requires a SSL connection please go to {0}", sslUrl));
    Response.End();

    // Or simply redirect
    // Response.Redirect(sslUrl);
}

I will encourage you to use WCF instead of ASMX http://msdn.microsoft.com/en-us/library/aa480190.aspx.

For your above question, does this solve your issue?

http://msdn.microsoft.com/en-us/library/aa302409.aspx

Thanks...

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!