简体   繁体   中英

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. If requested, it will work as https as well as http.

I ran the web API with https. All request and response operations are secure.

How can project run (Web and Web API projects) both with http and https?

Where and how do I have to manage / redirect requests that may come as http or 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. (Look picture)

On the web side of the project, url and port variants can be highly improved and defined independently. So I will not have a problem there.

RequireHttpsAttribute ( if have to use )

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

Web Properties Project Url

config.js (web-side)

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

You should change project property (Ctrl+W, P) 'SSL Enabled' to true. After this you will be able to request as http as well https at the same time. Project Properties

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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