2010-07-09 62 views
1

我正在建立一個應用程序(asp.net)與在線支付,所以我想讓這些支付頁面SSL啓用。我怎樣才能做到這一點.. 幫助我..安全webApplication

感謝

+0

[開發人員在構建公共網站之前應該知道什麼?](http://stackoverflow.com/questions/72394/what-should-a-developer-know-before-building-a-public-web-現場) – R0MANARMY 2010-07-09 14:32:49

回答

1

創建同級到

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); 
    } 
} 

然後爲需要SSL頁面從這個基類繼承:

public class Login : SecurePage 
{ 
    protected void Page_Load 
     (
     object sender, 
     EventArgs e) 
    { 
    } 
}