0

I have an asp.net web api and an Angular app that all lives in the same project file. My Angular app just uses .ts and .html files, and was wondering if there is a way to get a variable from my .NET global.asax into the Angular app somehow?

2 Answers2

0

You could use an ASP.NET HiddenField control. With it, you can pass a variable value from the server to the client or the other way too.

This SO post on the HiddenField control usage may be helpful.

JohnH
  • 1,646
  • 1
  • 22
  • 27
0

There are a couple different ways you can pass data from your web application to your client code. How you would go about it will depend on the type of web application you have (WebForms, MVC, API), and the amount of security you need. There are other ways then the following as well, if you provided more detail about what you are trying to do, then better suggestions can maybe be made.

  • You could set up an AJAX call in the client code to request the info from the server at runtime.
  • You could set the info in a cookie, and use the client code to read the contents of the cookie.
  • If you are using a web application that renders web pages, you can have the value rendered as a variable declaration in some client code.
  • If you are using a web application that renders web pages, you could also have the value rendered as a hidden field.

Please keep in mind that any data handled by the client side code exists on the client, and therefore can be accessed and even manipulated by the client. (Malisciously or accidentally)

MBurnham
  • 371
  • 1
  • 9