0

It is possible to create or emulate a virtual directory using C# for load controls (ascx) from a directory outside my web application scope?

Im trying :

 UserControl newUserControl = (UserControl)LoadControl( @"D:\" + ascxFileName);

Obviously I get runtime exception as the follow : 'D: \ ClaimOutputs \ SolicitudDatoIncorrecto_6.ascx' is not a valid virtual path.

Thanks

Jonathan Escobedo
  • 3,977
  • 12
  • 69
  • 90

1 Answers1

2

You will need to add a virtual directory in your IIS site that points to the other physical location.

There are a lot of security reasons why you can't just directly reference files outside of the directory structure your app is running in.

UPDATE:
Can you create a virtual directory in IIS with C#? yes. IIS does have an API. Creating Virtual directory in IIS with c#

However, the user the site runs under should never have the rights necessary to do that due to security concerns. You could set it up as a build process, provided you have the rights necessary to do this.

Community
  • 1
  • 1
NotMe
  • 87,343
  • 27
  • 171
  • 245
  • Before publishing my Website to a IIS Server could I create a virtual directory using C# in runtime, is this a valid solution? – Jonathan Escobedo Aug 15 '11 at 22:50
  • I need to debug de website before publishing to IIS, so I want to create a VirtualPath Folder or Directory when I launch Application_Start trough VS10 (runtime) so I will do some test... – Jonathan Escobedo Aug 16 '11 at 16:00
  • @Angel Escobedo: Just set up your local IIS with the appropriate virtual directory. Publish locally and debug away. – NotMe Aug 16 '11 at 16:48