I have to access the url without login, but it is redirected to login page. I wolud like to stop the redirection to login the page for my scenario. Could you please assist me
14 Answer(s)
-
0
- What is your product version?
- What is your product type (Angular or MVC)?
- What is product framework type (.net framework or .net core)?
-
0
ASP.NET CORE and Angular
-
0
You can try to modify it in auth-route-guard. https://github.com/aspnetzero/aspnet-zero-core/blob/e9517e1e64cc815f35290d242ec59840ea487eaa/angular/src/app/shared/common/auth/auth-route-guard.ts
-
0
I have used below code but it was not working.
if (_.includes(state.url, 'asap-sso')) { this._router.navigate(['app/main/asap-sso', 66]); return true; }
-
0
please show your full code of
auth-route-guard.ts
-
0
please show your full code of
auth-route-guard.ts
-
0
import { PermissionCheckerService } from '@abp/auth/permission-checker.service'; import { Injectable } from '@angular/core'; import { ActivatedRouteSnapshot, CanActivate, CanActivateChild, CanLoad, Router, RouterStateSnapshot } from '@angular/router'; import { AppSessionService } from '@shared/common/session/app-session.service'; import { UrlHelper } from '@shared/helpers/UrlHelper'; import { Data, Route } from '@node_modules/@angular/router/src/config'; import { Observable } from '@node_modules/rxjs/internal/Observable'; import * as _ from 'lodash'; @Injectable() export class AppRouteGuard implements CanActivate, CanActivateChild, CanLoad { constructor( private _permissionChecker: PermissionCheckerService, private _router: Router, private _sessionService: AppSessionService ) { } canActivateInternal(data: Data, state: RouterStateSnapshot): boolean { debugger; if (_.includes(state.url, 'asap-sso')) { this._router.navigate(['app/main/asap-sso', 66]); return true; } if (UrlHelper.isInstallUrl(location.href)) { return true; } if (!this._sessionService.user) { this._router.navigate(['/account/login']); return false; } if (!data || !data['permission']) { return true; } if (this._permissionChecker.isGranted(data['permission'])) { return true; } this._router.navigate([this.selectBestRoute()]); return false; } canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): boolean { return this.canActivateInternal(route.data, state); } canActivateChild(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): boolean { return this.canActivate(route, state); } canLoad(route: Route): Observable<boolean> | Promise<boolean> | boolean { return this.canActivateInternal(route.data, null); } selectBestRoute(): string { debugger; if (!this._sessionService.user) { return '/account/login'; } if (this._permissionChecker.isGranted('Pages.Administration.Host.Dashboard')) { //return '/app/admin/hostDashboard'; return '/app/admin/users'; } if (this._permissionChecker.isGranted('Pages.Tenant.Dashboard')) { return '/app/main/dashboard'; } if (this._permissionChecker.isGranted('Pages.Tenants')) { return '/app/admin/tenants'; } if (this._permissionChecker.isGranted('Pages.Administration.Users')) { return '/app/admin/users'; } return '/app/notifications'; } }
-
0
Try modifying
/account/login
to/app/main/asap-sso
https://github.com/aspnetzero/aspnet-zero-core/blob/e9517e1e64cc815f35290d242ec59840ea487eaa/angular/src/app/shared/common/auth/auth-route-guard.ts#L24 -
0
i have tried as you mentioned. But it is looping infinite time. The browser is freezing. The code is below:
canActivateInternal(data: Data, state: RouterStateSnapshot): boolean { debugger; //if (state != null) { // if (_.includes(state.url, 'asap-sso')) { // this._router.navigate(['app/main/asap-sso', 66]); // return true; // } //} if (UrlHelper.isInstallUrl(location.href)) { return true; } if (!this._sessionService.user) { //this._router.navigate(['/account/login']); this._router.navigate(['app/main/asap-sso']); return false; } if (!data || !data['permission']) { return true; } if (this._permissionChecker.isGranted(data['permission'])) { return true; } this._router.navigate([this.selectBestRoute()]); return false; }
-
0
You can consider moving the component asap-sso to the Account module or adding the following special judgment.
if (state != null) { if (_.includes(state.url, 'asap-sso')) { // Do not navigate. //this._router.navigate(['app/main/asap-sso', 66]); return true; } }
canActivateInternal(data: Data, state: RouterStateSnapshot): boolean { debugger; if (state != null) { if (_.includes(state.url, 'asap-sso')) { //this._router.navigate(['app/main/asap-sso', 66]); return true; } } if (UrlHelper.isInstallUrl(location.href)) { return true; } if (!this._sessionService.user) { //this._router.navigate(['/account/login']); this._router.navigate(['app/main/asap-sso']); return false; } if (!data || !data['permission']) { return true; } if (this._permissionChecker.isGranted(data['permission'])) { return true; } this._router.navigate([this.selectBestRoute()]); return false; } ```
-
0
Thanks @maliming. It is working now. Can you pls tell me why we not navigate.
-
0
If you call navigate, it will be intercepted again by AppRouteGuard. Infinite loop...
-
0
@maliming,
you solution not worked for me
-
0
@SRTMDEV Can you create a question separately and describe in detail the problem you are experiencing?