Secure webApplication
I am building an application(asp.net) with o开发者_StackOverflow社区nline payment so i want to make these payment page SSL enable. How can i do that.. Help me..
Thanks
Create class similar to
public class SecurePage : Page
{
protected override void OnInit( EventArgs e )
{
//retrieve appsettings value. set to false for localhost or dev environment
var sslRequired = bool.Parse(WebConfigurationManager.AppSettings["Security-SSL-Required"] ?? "true");
var currentUrl = System.Web.HttpContext.Current.Request.Url;
if (!currentUrl.Scheme.Equals(Uri.UriSchemeHttps, StringComparison.CurrentCultureIgnoreCase) && sslRequired)
{
//build the secure uri
var secureUrlBuilder = new UriBuilder(currentUrl);
secureUrlBuilder.Scheme = Uri.UriSchemeHttps;
//use the default port.
secureUrlBuilder.Port = -1;
//redirect and end the response.
System.Web.HttpContext.Current.Response.Redirect(secureUrlBuilder.Uri.ToString());
}
base.OnInit(e);
}
}
Then for pages that require SSL inherit from this base class:
public class Login : SecurePage
{
protected void Page_Load
(
object sender,
EventArgs e )
{
}
}
精彩评论