【问题标题】:Angular + .net Core 3 + Azure App Service- Allow HTTP on specific route only?Angular + .net Core 3 + Azure App Service - 仅在特定路由上允许 HTTP?
【发布时间】:2020-06-19 09:12:54
【问题描述】:
我的项目有一个有趣的场景。
我必须将 SOAP 服务(使用肥皂核心)部署到环境中,并且它必须允许 http——使用它的客户端应用程序是旧的、已经编译的,并且不能使用 https(我试过) .
但是,我只想要 http,而不是 https。
所以我正在寻找一个特定的路线:myservice/theservice.asmx 以允许 HTTPS,而其他一切都不是那么多。
我已部署到 Windows 应用服务中。
如果需要,我可以将此肥皂服务拆分为另一个应用服务,但我不希望这样做。
有没有办法做到这一点?
【问题讨论】:
标签:
angular
azure
asp.net-core
web
azure-web-app-service
【解决方案1】:
我找到了自己问题的答案:
app.UseWhen(httpContext => !httpContext.Request.Path.StartsWithSegments("/pga4"),
subApp => subApp.UseHttpsRedirection());
这允许您根据路径有条件地应用中间件。
(subApp 的行为与app.Usexxx() 相同,但仅在此条件上下文中)。
希望这会有所帮助。
【解决方案2】:
您可以使用HttpInterceptor 过滤和修复每个发出的http/s 请求吗?
一个非常粗略的例子:
import { Injectable } from '@angular/core';
import {
HttpRequest,
HttpHandler,
HttpEvent,
HttpInterceptor
} from '@angular/common/http';
@Injectable()
export class ServiceInterceptor implements HttpInterceptor {
intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
if (request.url.match(/myservice\/theservice\.asmx$/)) {
request = request.clone({
url: request.url.replace('https:', 'http:')
});
}
return next.handle(request);
}
}