[英]How is it possible to run Angularjs webapi at the same time as http and https?
我想為基於Web的angularJS項目提供http和https支持。 如果要求,它將與https以及http一樣工作。
我使用https運行了Web API。 所有請求和響應操作都是安全的。
如何同時使用http和https運行項目(Web和Web API項目)?
我在哪里以及如何管理/重定向可能以http或https發出的請求?
我認為有些事情可以幫助您解決這個問題。 在Web API的配置選項中,項目/網址僅允許使用一個值。 (看圖片)
在項目的Web端,可以極大地改進和獨立定義url和port變體。 所以我在那里不會有問題。
RequireHttpsAttribute (如果必須使用)
public override void OnAuthorization(HttpActionContext actionContext)
{
//if (actionContext.Request.RequestUri.Scheme != Uri.UriSchemeHttps)
//{
// actionContext.Response = actionContext.Request.CreateResponse(HttpStatusCode.Found);
// actionContext.Response.Content = new StringContent("<span> Http yerine artık https kullanılıyor.</span>");
// UriBuilder uriBuilder = new UriBuilder(actionContext.Request.RequestUri);
// uriBuilder.Scheme = Uri.UriSchemeHttps;
// uriBuilder.Port = 44332;
// actionContext.Response.Headers.Location = uriBuilder.Uri;
//}
//else
//{
// base.OnAuthorization(actionContext);
//}
}
WebAPI屬性 項目網址
網站資源 項目網址
config.js (網絡端)
//serviceBase: "http://localhost:61456/",
//servicePort: "61456",
serviceBase: "https://localhost:44332/",
servicePort: "44332"
您應該將項目屬性(Ctrl + W,P)“啟用SSL”更改為true。 之后,您將可以同時請求http和https。 項目屬性
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.