0

There is a way to read web.config settings inside an activex code? I need to set connectionstring inside my activex.

2
  • Do you mean ActiveX controls inside ASP.NET / MVC pages?
    – Roy Dictus
    Jan 29, 2013 at 14:39
  • Yes ActiveX control inside my ASP.NET site
    – mantok
    Jan 29, 2013 at 14:58

1 Answer 1

2

ActiveX controls run in the browser, hence they have no access to Web.config.

What you can do is expose properties in your controls and then fill in those properties in your code behind (C#/VB.NET) or .ASPX pages. Server-side code does have access to Web.config, so it can read the data from there and pass it on to the ActiveX controls by filling in the properties.

Alternatively, you could write code in your ASP.NET page that generates client-side JavaScript, and this JavaScript can then fill in the ActiveX control's properties. It's the same thing, really, because you're always accessing the config file from your server-side code and passing on the data to the ActiveX control, either by generating HTML or by generating JavaScript.

2
  • Thank you, the problme is that data is sensible data, like connection string to access to database
    – mantok
    Jan 29, 2013 at 19:19
  • If the data is sensitive, you may want to bake it right into the ActiveX control rather than expose it as a property, if possible. But even then there remains a possibility that the connection string is discovered. A better option is probably not to let the control talk to your database, but rather have your server-side code talk to the database and then feed the results to your page. Another option would be to let the ActiveX control talk to a Web service instead, and to use some kind of security mechanism so that the service only sends data the user has a right to see.
    – Roy Dictus
    Jan 30, 2013 at 9:10

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.