1

I am having an ASP.NET WebForms application in which I am trying to integrate Angular.

To keep it simple, I have a Login.aspx and Dashboard.aspx.

Login.aspx has a 'Login' button and on its 'click' event handler i'm redirecting to the Dashboard.aspx with below line of code:

Response.Redirect("Dashboard.aspx?auth-token=abcd1234");

I have integrate Angular in the Dashboard.aspx page and the markup for it is as below:

<head>
    <meta charset="utf-8">
    <base href="/NgDashboard/">
    <meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
    <app-root></app-root>
    <script src="runtime-es2015.js" type="module"></script>
    <script src="runtime-es5.js" nomodule defer></script>
    <script src="polyfills-es5.js" nomodule defer></script>
    <script src="polyfills-es2015.js" type="module"></script>
    <script src="styles-es2015.js" type="module"></script>
    <script src="styles-es5.js" nomodule defer></script>
    <script src="vendor-es2015.js" type="module"></script>
    <script src="vendor-es5.js" nomodule defer></script>
    <script src="main-es2015.js" type="module"></script>
    <script src="main-es5.js" nomodule defer></script>
</body>

Now when I run the asp.net application's Login.aspx, I have the URL as:

https://localhost:44303/Login.aspx

And when I click on 'Login', I want the URL to be as:

https://localhost:44303/Dashboard.aspx?auth-token=abcd1234

To prevent Angular from changing the URL I have made the below change to the AppRoutingModule (as per this link):

RouterModule.forRoot(routes, {
      initialNavigation: false
    })

I have not added any other routes in my angular application. So I'm trying to read the query string parameter 'auth-token' inside the AppComponent with the below code:

ngOnInit(): void {
    this.route.queryParams.subscribe(params => {
      this.queryStringAuthToken = params["auth-token"];
    });

Now, even though I'm able to get the url as expected, the angular app is not reading able to read the query string parameter.

So how can I read the query string parameters from Angular when I redirect from one aspx page to a second aspx page which has the angular app inside it?

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.