У нас есть интерфейс Angular4, который вызывает веб-API ASP.NET Core 2.0, размещенный в IIS, с использованием проверки подлинности Windows. При загрузке внешнего интерфейса в первый раз или в режиме инкогнито требуется вход в систему, но после успешного входа в систему не выполняется перенаправление обратно на интерфейсную часть. Происходит это так:
http://localhost:4200
http://localhost:53465
.http://localhost:53465
вместо перенаправления на http://localhost:4200
.Все это началось недавно с последним обновлением Chrome, раньше это никогда не было проблемой; после входа в систему вы будете перенаправлены на интерфейс, к какой бы странице вы ни намеревались перейти.
Вот что у нас есть для web.config на интерфейсном сайте:
<?xml version = "1.0" encoding = "utf-8" ?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name = "Angular" stopProcessing = "true">
<match url = ".*" />
<conditions logicalGrouping = "MatchAll">
<add input = "{REQUEST_FILENAME}" matchType = "IsFile" negate = "true" />
<add input = "{REQUEST_FILENAME}" matchType = "IsDirectory" negate = "true" />
</conditions>
<action type = "Rewrite" url = "/" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
Вот файл web.config для сайта API:
<?xml version = "1.0" encoding = "utf-8"?>
<configuration>
<appSettings>
<add key = "autoFormsAuthentication" value = "false" />
<add key = "enableSimpleMembership" value = "false" />
<add key = "PreserveLoginUrl" value = "true" />
</appSettings>
<system.web>
<authentication mode = "Windows" />
</system.web>
<system.webServer>
<handlers>
<remove name = "aspNetCore" />
<add name = "aspNetCore" path = "*" verb = "*" modules = "AspNetCoreModule" resourceType = "Unspecified" />
</handlers>
<aspNetCore processPath = "%LAUNCHER_PATH%" arguments = "%LAUNCHER_ARGS%" stdoutLogEnabled = "false" stdoutLogFile = ".\logs\stdout" startupTimeLimit = "3600" requestTimeout = "23:00:00" forwardWindowsAuthToken = "true" />
<security>
<authorization>
<remove users = "*" roles = "" verbs = "" />
<add accessType = "Allow" users = "?" verbs = "OPTIONS" />
<add accessType = "Allow" roles = "USERS" />
</authorization>
</security>
</system.webServer>
</configuration>
Вот как мы делаем наши HTTP-запросы в Angular:
getPendingRequests(owner: string): Observable<any[]> {
let url = `${this.baseUrl}pending`;
return this._http.get(url).map((res: Response) => res.json());
}
и параметры, которые отправляются вместе с ним:
@Injectable()
export class NoCacheRequestOptions extends BaseRequestOptions {
constructor () {
super();
this.headers.append('Cache-Control','no-cache');
this.headers.append('Pragma', 'no-cache');
this.headers.append('Expires', 'Sat, 01 Jan 2000 00:00:00 GMT');
this.headers.append('Content-Type', 'application/json');
this.withCredentials = true;
}
}
Вот пример конечной точки API:
[Route("pending")]
[Authorize]
public class PendingCorrespondenceController : Controller
{
....
public async Task<IActionResult> GetPendingCorrespondence()
{
И наш Startup.cs для API:
public void ConfigureServices(IServiceCollection services)
{
services.AddSingleton(Configuration);
services.AddMemoryCache();
services.AddMvc();
services.AddAuthentication(IISDefaults.AuthenticationScheme);
services.AddAuthentication("CookieAuthenticationScheme")
.AddCookie("CookieAuthenticationScheme");
services.AddCors(options =>
{
options.AddPolicy("AllowSpecificOrigin", builder =>
{
builder.WithOrigins(Configuration["CORS:AllowedOrigins"]);
builder.AllowCredentials();
builder.AllowAnyHeader();
builder.AllowAnyMethod();
});
});
services.AddSingleton<IDashboardData, CacheDashboardData>();
services.AddSingleton<ICorrespondencePermission, CorrespondencePermission>();
services.AddSingleton<IPendingCorrespondence, PendingCorrespondence.PendingCorrespondence>();
services.AddSingleton<IHoldForReview, HoldForReview.HoldForReview>();
services.AddSingleton<IActiveDirectory, ActiveDirectory>();
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment()) app.UseDeveloperExceptionPage();
app.UseAuthentication();
app.UseCors("AllowSpecificOrigin");
app.UseMiddleware<PermissionsMiddleware>();
app.UseMiddleware<GlobalExceptionLogger>();
app.UseMvc().UseMvcWithDefaultRoute();
}
Мы боролись с этим в течение пары дней, но безуспешно, есть ли что-то очевидное, что нам не хватает?
К сожалению, мы не нашли решения, и нам пришлось прибегнуть к объединению API и UI на одном сервере / порту.
У нас такая же проблема с AngularJS, вы нашли решение?