Showing posts with label Route. Show all posts
Showing posts with label Route. Show all posts

Saturday, March 14, 2020

How to get the name of the route the user try to navigate on canAcitvate method?

when we want to know what component the use try to access with AuthGuard enable, it is quit simple

we can put a console.log in the canActivate Method, to monitor the ActivateRouteSnapshot in Angular 9


console.log("the name of route: " + destination.routeConfig.component.name);
 

in Angular 6

you can access it from route.component.name

here is the sample code


import { Injectable } from "@angular/core";
import { CanActivateRouterActivatedRouteSnapshot 
RouterStateSnapshot } from '@angular/router';

@Injectable()
export class longinGuard implements CanActivate{
    constructor(private routerRouter){

    }
    canActivate(destinationActivatedRouteSnapshotstateRouterStateSnapshot){
        console.log("the name of route navigate to: " +
  destination.routeConfig.component.name);
  
    }
}

Monday, April 27, 2015

How to fix "CS0103: The name 'Scripts' or 'Content' does not exist in the current context" Error in MVC Share Assembly

when i try to integrate a MVC share assembly(which is running under Web Razor View Engine) into a MVC web project which runing with WebForm view engine.

i go the following error message :Compiler Error Message: CS0103: The name 'Styles' does not exist in the current context




the solution is to follow the steps.

1. add  <add namespace="System.Web.Optimization" /> to the web.config file under the Views folder in the MVC Share Assembly project.

2. install "Mincrosoft Asp.net Web Optimization Framework" package via the Manage NuGet Package Window to the MVC share assembly project.



 3. added Bundle Configuration Logic to Global.asax in the MVC WebForm Project

 protected void Application_Start()
        {
            MvcRazor.SetupMvcRazor.Setup();

            AreaRegistration.RegisterAllAreas();

            RegisterRoutes(RouteTable.Routes);
            RegisterBundles(BundleTable.Bundles);
        }

        protected void RegisterBundles(BundleCollection bundles)
        {
            bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
                        "~/Scripts/jquery-{version}.js"));

            bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include(
                        "~/Scripts/jquery.validate*"));

            // Use the development version of Modernizr to develop with and learn from. Then, when you're
            // ready for production, use the build tool at http://modernizr.com to pick only the tests you need.
            bundles.Add(new ScriptBundle("~/bundles/modernizr").Include(
                        "~/Scripts/modernizr-*"));

            bundles.Add(new ScriptBundle("~/bundles/bootstrap").Include(
                      "~/Scripts/bootstrap.js",
                      "~/Scripts/respond.js"));

            bundles.Add(new StyleBundle("~/Content/css").Include(
                      "~/Content/bootstrap.css",
                      "~/Content/site.css"));
        }

then you will see MVC share assembly page from the MVC Web Form Application.