locked
ASP.global_asax Type RRS feed

  • Question

  • User1557998713 posted

    From Session_Start I call: MyFunction (this) that detects the type of system in use. Upon receiving this in the function, I look in the debug and indicate that "this" is type "dynamic {ASP.global_asax}". If I enter "this is ASP.global_asax" answer true. But it does not allow me to write this same line in code.

    1.- How can I detect the type ASP.global_asax
    2.- What is the correct way to detect the Aspx system. I now use System.Web.HttpContext.Current! = Null

    Saturday, December 28, 2019 3:53 PM

All replies

  • User475983607 posted

    From Session_Start I call: MyFunction (this) that detects the type of system in use. Upon receiving this in the function, I look in the debug and indicate that "this" is type "dynamic {ASP.global_asax}". If I enter "this is ASP.global_asax" answer true. But it does not allow me to write this same line in code.

    1.- How can I detect the type ASP.global_asax
    2.- What is the correct way to detect the Aspx system. I now use System.Web.HttpContext.Current! = Null

    Well, the keyword "this" in Session_Start refers to the Global_asax class since Session_Start is a member of the Global_asax class.  The same holds true for any class in the .NET framework.  

    Can you explain the problem you are string to solve? 

    Saturday, December 28, 2019 4:02 PM
  • User1557998713 posted

    From WPF and WinForms (from Mainform) and ASPX (from global.asax) I call a function with parameter "this" to detect the type of system I am using. I want to check "this" in the case of ASP.global_asax  The VS source code editor does not allow me to write if (this is ASP.global.asax) ...

    Saturday, December 28, 2019 4:22 PM
  • User475983607 posted

    From WPF and WinForms (from Mainform) and ASPX (from global.asax) I call a function with parameter "this" to detect the type of system I am using. I want to check "this" in the case of ASP.global_asax  The VS source code editor does not allow me to write if (this is ASP.global.asax) ...

    You are mistaken.  The "this" keyword in C# refers to the current class instance.  See the C# reference documentation. 

    https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/this

    Saturday, December 28, 2019 6:11 PM
  • User1557998713 posted

    You will notice that after your answer, I have not marked "Solved."

    Sunday, December 29, 2019 5:50 AM
  • User753101303 posted

    Hi,

    does not allow

    Tell rather what happens. My guess is that this type is not known to your library and anyway it would be not the same type in all and every web app. A quick fix might to check the base type ie:

    if (this is System.Web.HttpApplication) // do whatever... global_asax should inherit from HttpApplication

    For a better suggestion we would need to understand the purpose of testing ithis (what if called from ASP.NET Core, from a Windows service and so on ?), maybe injecting a dependency suitable for the current environment??

    Sunday, December 29, 2019 9:43 AM
  • User1557998713 posted

    This is my code:

    // WINFORMS.
    if (this is System.Windows.Forms.Form)...
    // WPF.
    if (this is System.Windows.Window) ...
    // ASPX.  I need to know this
    // if (this is ASP.global_asax) ...

    and if this fails:

    // WINFORMS.
    if (System.Windows.Forms.Application.OpenForms.Count > 0)...
    // WPF.
    if (System.Windows.Application.Current != null)...
    // ASPX.
    if (System.Web.HttpContext.Current != null)...

    Sunday, December 29, 2019 2:48 PM
  • User409696431 posted

    Is this a Windows Forms application?  FYI you are posting in a Web Forms forum.

    Sunday, December 29, 2019 8:18 PM