locked
web application where to declare variables RRS feed

  • Question

  • User2146470223 posted

    Hi,

    Up to now I had a web site solution which I converted to a web application. When doing this my App_Code foder also got converted to Old_App_Code. In that folder I had several files where I declared variables (formbase, subs) to be used in all files.

    Where were they moved during conversion or: where in web application do I declare variables that I want to use in several files?

    regards,

    Pascal

    Tuesday, December 11, 2018 11:57 PM

Answers

  • User2146470223 posted

    As I could not find any dll for these files, and the only files I found containing the variables through searching in solution explorer are the files contained within Old_App_Code, I thus tried adding variables there and it seems to work.

    Although I thought thi was just a folder for obsolete files, if I get it right, I just can go on with these files that are now in another folder.

    Could anyone confirm this?

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, December 12, 2018 11:04 PM
  • User475983607 posted

    Although I thought thi was just a folder for obsolete files, if I get it right, I just can go on with these files that are now in another folder.

    Could anyone confirm this?

    Visual Studio complies all the cs files within the web application project into a DLL.  

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, December 12, 2018 11:54 PM

All replies

  • User475983607 posted
    Variable declaration is no different in an application than a site project. The same C# language constructs apply across all project types. Can you post source code that illustrates your programming problem?
    Wednesday, December 12, 2018 12:10 AM
  • User2146470223 posted

    Hi mgebhard,

    I'm using VB not C# ;).

    In my web site project I declared all variables in one file under App_Code so that I could reuse them throughout all files using

    Protected ordert As String

    but I can't see where this file went during conversion so that I could just add new variables there instead of directly in the file where I need them.

    Wednesday, December 12, 2018 9:16 AM
  • User753101303 posted

    Hi,

    And it is in a class ? App_Code is to compile code on the fly when the site is hit for the first time. Now it should be compiled when the app is published but AFAIK it should work basically unchanged. The namespace may differ though.

    Once the conversion is done you have compile time errors ?

    Wednesday, December 12, 2018 10:00 AM
  • User2146470223 posted

    Hi PatriceSc,

    You mean in App_Code in web site project? Yes, file name was subs.vb with Class subs.

    I don't have the project files at hand right now but I had some errors with missing variables but in files I realized did not reference these files for some reason so I wanted to add the missing variables and a refernce to the class but don't know how if I don't know where they are hiding now.

    Wednesday, December 12, 2018 1:03 PM
  • User-943250815 posted

    Whenever you need to reference some public class in another file in App_Code folder, just use "Import <main class name>" of subs.vb (in your case), this should be placed on top of the file you need a reference or access to classes in another file

    https://docs.microsoft.com/en-us/dotnet/visual-basic/language-reference//statements/imports-statement-net-namespace-and-type

    Wednesday, December 12, 2018 3:36 PM
  • User2146470223 posted

    Jzero

    You don't get the point. That folder does not exist anymore as web site solution was converted to web application solution. That's why I have to the problem to find the file within the newly converted solution in order to add or change existing variables.

    Wednesday, December 12, 2018 3:39 PM
  • User753101303 posted

    The "Old_App_Code" folder you talked earlier is empty ?

    I would expect App_Code to be renamed. The special App_Code folder is to compile code on the fly so when converting your web site to a web app I woulkd expect this folder to be renamed so that the code it contains is compiled earlier when the app is published. Else I would have to give this a try as it's been a while. If I remember the code in App_Code was in a particular namespace which might be the issue ???

    Wednesday, December 12, 2018 3:41 PM
  • User2146470223 posted

    Hi Patrice,

    As stated above it was renamed. No that folder is not empty, it contains all files that existed in the converted App_Code folder but I understood that these files should now be part of some dll. Or did I get this wrong?

    App_Code should not be used in WAP because it would force the site to recreate the dll VS already created and cause issues with existing classes and references.

    Wednesday, December 12, 2018 3:55 PM
  • User-943250815 posted

    Oops, I didn't pay proper attention.
    Personally, I did not made such conversion, but I found (perhaps redundant for you) some gotchas related to "Namespace"
    https://stackoverflow.com/questions/735054/how-to-convert-asp-net-website-to-asp-net-web-application
    https://docs.microsoft.com/en-us/previous-versions/aa983476(v=vs.140)

    Wednesday, December 12, 2018 4:04 PM
  • User2146470223 posted

    Hi Jzero,

    had not yet found/visited the first link but I did for the other one. Unfortunately the new link contains nothing which would help me answer my question.

    Wednesday, December 12, 2018 4:14 PM
  • User2146470223 posted

    As I could not find any dll for these files, and the only files I found containing the variables through searching in solution explorer are the files contained within Old_App_Code, I thus tried adding variables there and it seems to work.

    Although I thought thi was just a folder for obsolete files, if I get it right, I just can go on with these files that are now in another folder.

    Could anyone confirm this?

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, December 12, 2018 11:04 PM
  • User475983607 posted

    Although I thought thi was just a folder for obsolete files, if I get it right, I just can go on with these files that are now in another folder.

    Could anyone confirm this?

    Visual Studio complies all the cs files within the web application project into a DLL.  

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, December 12, 2018 11:54 PM
  • User753101303 posted

    Yes, as I tried to tell this folder is renamed so that the usual behavior for the special App_Code folder (ie compiling code directly on the web site rather than at publish time) doesn't happen any more.

    Friday, December 14, 2018 6:02 PM