Click here to Skip to main content
15,910,981 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have a dot.net project in which Global.asax file was there but Global.asax.cs(vb) was not there. So I deleted the old one Global.asax file and created the new one using the Global template in visualstudio 2013 because i want to perform some function in APPlication_Start event of Global.asax.vb

code of GLOBL .asax
<%@ Application Codebehind="Global.asax.vb" Inherits="WebApp.Global_asax" Language="vb" %>

Code if Global.asax.vb

Public Class Global_asax
Inherits System.Web.HttpApplication

Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
Dim key As String = String.Empty
If (key Is Nothing) OrElse (key Is "") Then
key = GetJwtTokenFromSource("4201.omse.jul.web", "read_master_reference","", "", "")
key = Convert.ToString("Bearer ") & key
End If

CallNM(NMPCodes.LEVEl, key)
CallNM(MMPCodes.GROUP, key)

End Sub
task that i want to perform in start even is running fine but after successfull execution of this block I am getting below exception.

'Unable to cast object of type 'ASP._global_asax' to type 'Microsoft.Practices.CompositeWeb.WebClientApplication'

What I have tried:

If I am inherting GLOBAL.ASAX from Microsoft.Practices.CompositeWeb.WebClientApplication

code of GLOBL .asax
<%@ Application Codebehind="Global.asax.vb" Inherits="Microsoft.Practices.CompositeWeb.WebClientApplication" Language="vb" %>
Then Application_start event is not firing.
Posted
Updated 1-Nov-17 4:49am
Comments
F-ES Sitecore 18-Jan-17 9:01am    
You are saying the is asax that the page inherits Microsoft.Practices.CompositeWeb.WebClientApplication so the class in the code behind file must also be derived from that class, and yours is not. Either change the class in the code behind or change the inherits tag to Global_asax, whichever is right for your solution.
TarunShrivastav 19-Jan-17 4:51am    
If i am inheriting Asax and code behind file both with Microsoft.Practises.CompositeWeb.WebClientApplication then Application_start event of my .cs class is not getting executed.

The Inherits attribute in the .asax file needs to be the name of the class in the .asax.vb file.

The class in the .asax.vb file needs to inherit from the composite web base-class.

Global.asax:
<%@ Application Codebehind="Global.asax.vb" Inherits="WebApp.Global_asax" Language="vb" %>

Global.asax.vb:
Public Class Global_asax
    Inherits Microsoft.Practices.CompositeWeb.WebClientApplication
    
    ...
End Class
 
Share this answer
 
Comments
TarunShrivastav 18-Jan-17 22:08pm    
Thanks for your response but I did the above changes as suggested by you. Still the same thing is happening Application_Start is not getting triggered. It is executing some other function.

And visual studio is showing a message : sub Application_start shadows an override method in base class webclientApplication. To override the base method, This method must be declared override.
Richard Deeming 19-Jan-17 8:26am    
So follow the instructions in the message - declare the method as an override, and call the base method.
Protected Overrides Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
    MyBase.Application_Start(sender, e)
    ...
TarunShrivastav 23-Jan-17 4:40am    
Thanks for the solution. Now it is working as expected after overriding the method.
Hi,

I am working on an obsolete project ( in VS 2008) and today while migrating my website to IIS 7 i faced this issue.

I did two things
a. Checked and removed unrequired default document from IIS.
b. Deleted the precompiledapp.config and it start to work as before.

Hope it works for you.

Thanks
Rajkamal
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900