简体   繁体   English

如何与http和https同时运行Angularjs webapi?

[英]How is it possible to run Angularjs webapi at the same time as http and https?

I want to provide http and https support for web based angularJS project. 我想为基于Web的angularJS项目提供http和https支持。 If requested, it will work as https as well as http. 如果要求,它将与https以及http一样工作。

I ran the web API with https. 我使用https运行了Web API。 All request and response operations are secure. 所有请求和响应操作都是安全的。

How can project run (Web and Web API projects) both with http and https? 如何同时使用http和https运行项目(Web和Web API项目)?

Where and how do I have to manage / redirect requests that may come as http or https? 我在哪里以及如何管理/重定向可能以http或https发出的请求?

There is something that I think will help you with the question. 我认为有些事情可以帮助您解决这个问题。 In the configure options of Web API, only one value is allowed as project / url. 在Web API的配置选项中,项目/网址仅允许使用一个值。 (Look picture) (看图片)

On the web side of the project, url and port variants can be highly improved and defined independently. 在项目的Web端,可以极大地改进和独立定义url和port变体。 So I will not have a problem there. 所以我在那里不会有问题。

RequireHttpsAttribute ( if have to use ) 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 Properties Project Url WebAPI属性 项目网址

Web Properties Project Url 网站资源 项目网址

config.js (web-side) config.js (网络端)

//serviceBase: "http://localhost:61456/",
//servicePort: "61456",
serviceBase: "https://localhost:44332/",
servicePort: "44332"

You should change project property (Ctrl+W, P) 'SSL Enabled' to true. 您应该将项目属性(Ctrl + W,P)“启用SSL”更改为true。 After this you will be able to request as http as well https at the same time. 之后,您将可以同时请求http和https。 Project Properties 项目属性

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM