Issues with WebSite to WebApplication conversion - asp.net

I converted a website to a web application using visual studio 2017.After conversion the web application throws the following error.Is there any solution to this problem
Parser Error Message: The file '/Global.asax.vb' does not exist.
Source Error:
Line 1: <%# Application Inherits="WebApplication1.Test.Global"
Language="VB" CodeFile="Global.asax.vb" %

Open NOTEPAD application with a blank document.
Paste the following code into it
Option Explicit On
Imports Microsoft.VisualBasic
Imports System.Web.SessionState
Public Class Global_asax
Inherits System.Web.HttpApplication
'
Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
' Fires when the application is started
End Sub
Sub Session_Start(ByVal sender As Object, ByVal e As EventArgs)
' Fires when the session is started
End Sub
Sub Application_BeginRequest(ByVal sender As Object, ByVal e As EventArgs)
' Fires at the beginning of each request
End Sub
Sub Application_AuthenticateRequest(ByVal sender As Object, ByVal e As EventArgs)
' Fires upon attempting to authenticate the use
End Sub
Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
' Fires when an error occurs
End Sub
Sub Session_End(ByVal sender As Object, ByVal e As EventArgs)
' Fires when the session ends
End Sub
Sub Application_End(ByVal sender As Object, ByVal e As EventArgs)
' Fires when the application ends
End Sub
End Class
Save the file as GLOBAL.ASAX in the ROOT folder of your application where the code is.
Next which ever file has the error flagged it:
Line 1: <%# Application Inherits="WebApplication1.Test.Global" Language="VB" CodeFile="Global.asax.vb" %>
Change that line to the below:
<%# Application Inherits="WebApplication1.Test.Global" Language="VB" %>
Without seeing some of your code as there is no code posted, its difficult to nail it down straight away.
If you follow the above, it should get you past the error you displayed.

Related

How do i keep a record/count how many people visit my site?

Hi every one I have simple web app published on Internet Click to see that count the number of visitors and it's work fine with that but the problem is the counter is keep reset to default NO.0 I want the counter to keep it's value without reset and my code in Global.asax is
<%# Application Language="VB" %>
Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
' Code that runs on application startup
' Code that runs on application startup
Application("SiteVisitedCounter") = 5000
'to check how many users have currently opened our site write the following line
Application("OnlineUserCounter") = 0
End Sub
Sub Application_End(ByVal sender As Object, ByVal e As EventArgs)
' Code that runs on application shutdown
End Sub
Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
' Code that runs when an unhandled error occurs
End Sub
Sub Session_Start(ByVal sender As Object, ByVal e As EventArgs)
' Code that runs when a new session is started
Application.Lock()
Application("SiteVisitedCounter") = Convert.ToInt32(Application("SiteVisitedCounter")) + 1
'to check how many users have currently opened our site write the following line
Application("OnlineUserCounter") = Convert.ToInt32(Application("OnlineUserCounter")) + 1
Application.UnLock()
End Sub
Sub Session_End(ByVal sender As Object, ByVal e As EventArgs)
' Code that runs when a session ends.
' Note: The Session_End event is raised only when the sessionstate mode
' is set to InProc in the Web.config file. If session mode is set to StateServer
' or SQLServer, the event is not raised.
Application.Lock()
Application("OnlineUserCounter") = Convert.ToInt32(Application("OnlineUserCounter")) - 1
Application.UnLock()
End Sub
and In the Code Behind is
Label3.Text = Application("SiteVisitedCounter").ToString()
Label4.Text = Application("OnlineUserCounter").ToString()

use Application variable in asp to asp.net

i am converting a old application from asp classic to ASP.net VB. i find a code part in classic version where application variable is declared and i want to use this in my ASP.NET in Globel.asax file. I am getting confuse how i use this in my ASP.NET in globel.asax
ASP Classic Code
if application("noticeupdate")="OPEN" or application("noticeupdate")="CLOSED" then
else
application("noticeupdate")="OPEN"
end if
ASP.NET
Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
' Fires when the application is started
'Dim
If Application("noticeupdate") = "OPEN" Or Application("noticeupdate") = "CLOSED" Then
Else
Application("noticeupdate") = "OPEN"
End If
End Sub
Can you help me how can i convert this function .
Thanks for your reply
This is the syntax for same thing, I am not really understanding your code however...
Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
' Fires when the application is started
if application("noticeupdate")="OPEN" or application("noticeupdate")="CLOSED" then
...
else
application("noticeupdate")="OPEN"
end if
End Sub
You can read more here regarding application state:
http://msdn.microsoft.com/en-us/library/ms178594(v=vs.100).aspx
And on the page you can do something like this to display the value:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
Label1.Text = application("noticeupdate")
'or Response.Write application("noticeupdate")
End Sub

ASP.NET Issues with global.asax on GoDaddy.com

I am using Visual Studio 2012 to upload my website and having trouble getting it to show in my domain. Everything uploads on GoDaddy ftp. I talked with GoDaddy and they said that my global.asax file was causing the issue. But they couldn't tell me exactly what is was because they are not experts in code. He verified that the global.asax was the issue and not the web.config file. I have provided my global.asax file below. Any help would be awesome so I could get this website published and working on my domain. Thanks!
Imports System.Web.Optimization
Public Class Global_asax
Inherits HttpApplication
Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
' Fires when the application is started
BundleConfig.RegisterBundles(BundleTable.Bundles)
AuthConfig.RegisterOpenAuth()
RouteConfig.RegisterRoutes(RouteTable.Routes)
End Sub
Sub Application_BeginRequest(ByVal sender As Object, ByVal e As EventArgs)
' Fires at the beginning of each request
End Sub
Sub Application_AuthenticateRequest(ByVal sender As Object, ByVal e As EventArgs)
' Fires upon attempting to authenticate the use
End Sub
Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
' Fires when an error occurs
End Sub
Sub Application_End(ByVal sender As Object, ByVal e As EventArgs)
' Fires when the application ends
End Sub
End Class
Try adding an empty Global.asax file, e.g. commenting all the code lines from it, as it is in the code snippet below.
Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
' Fires when the application is started
' BundleConfig.RegisterBundles(BundleTable.Bundles)
' AuthConfig.RegisterOpenAuth()
' RouteConfig.RegisterRoutes(RouteTable.Routes)
End Sub
A next step is to uncomment one at a time and then detect the one that is causing the error.
Add the following lines to your web.config file
<system.webServer>
<modules runAllManagedModulesForAllRequests="true">
</modules>
</system.webServer>

Page.Init and Page.PostBack

I know this is a very basic question, but I cannot find the answer. There are lots of web pages that say page.init does not fire on a post back e.g. here: http://www.dotnetfunda.com/interview/exclusive/x3224-what-is-the-difference-between-the-pageinit-and-pageload-events.aspx. Please see the code below:
Public Class _Default
Inherits System.Web.UI.Page
Private Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
MsgBox("Test Init") 'Line 5
End Sub
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Page.IsPostBack = True Then
MsgBox("PostBack") 'line 9
End If
MsgBox("Test Load")
End Sub
Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
TextBox1.Text = "Hello"
End Sub
End Class
The message box on line 5 and line 9 fire every time I click the button. This means that the Init event is fired on a postback. I have obviously forgotten something very basic.
From your reference page:
When you postback to any page, the Page_Init event doesn't fire.
This is totally wrong.
Page_Init is always fired - actually the page cycle is not change at all.

Global.asax breaks with AJAX Control Toolkit

Everything was working fine. Then I added the Global.asax and suddenly got this error:
Line: 4723
Error: Sys.WebForms.PageRequestManagerParserErrorException: The message received from the server could not be parsed. Common causes for this error are when the response is modified by calls to Response.Write(), response filters, HttpModules, or server trace is enabled.
Details: Error parsing near 'eeCtrl_Data = null;|
<%# Application Language="VB" %>
<script runat="server">
Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
' Code that runs on application startup
End Sub
Sub Application_End(ByVal sender As Object, ByVal e As EventArgs)
' Code that runs on application shutdown
End Sub
Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
' Code that runs when an unhandled error occurs
End Sub
Sub Session_Start(ByVal sender As Object, ByVal e As EventArgs)
' Code that runs when a new session is started
End Sub
Sub Session_End(ByVal sender As Object, ByVal e As EventArgs)
' Code that runs when a session ends.
' Note: The Session_End event is raised only when the sessionstate mode
' is set to InProc in the Web.config file. If session mode is set to StateServer
' or SQLServer, the event is not raised.
End Sub
Protected Sub Application_BeginRequest(ByVal sender As Object, ByVal e As System.EventArgs)
HttpContext.Current.Items("renderStartTime") = DateTime.Now
End Sub
Protected Sub Application_EndRequest(ByVal sender As Object, ByVal e As System.EventArgs)
Dim startTime As DateTime = CType(HttpContext.Current.Items("renderStartTime"), DateTime)
Dim renderTime As TimeSpan = DateTime.Now - startTime
HttpContext.Current.Response.Write("<!-- Render Time (in milliseconds): " & renderTime.TotalMilliseconds.ToString & " -->")
End Sub
Try commenting out this line and see if that fixes it.
HttpContext.Current.Response.Write("<!-- Render Time (in milliseconds): " & renderTime.TotalMilliseconds.ToString & " -->")
HTH.
This is not elegant, but it works for my needs (thankfully this is an internal app). It's a two-part solution. One is for the postbacks that occur due to an UpdatePanel postback. The other is for regular postback.
I'd rather not close this thread, because I think better solutions can be presented.

Resources