I have an MVC3 application, trying to register/run this in IIS (6.1 and 7.5 Express) so I can run it as a local server and debug it via VS2010. For some reason the events in the Global.asax.cs file are not firing. Namely Application_Start so consequently, the RegisterRoutes is also not being called.
I use Re-sharper and it's telling me Application_Start() is never used which is strange as when I use the ASP.NET local web server (Project Properties, Use Visual Studio Development Server) this is called and executed as expected.
The problem seems to lie with running the app via IIS??
The file is a .cs file so I tried creating a Global.asax and inheriting the Global.asax.cs as per code behind. I also looked in IIS Manager > Handler Mappings > ExtensionlessUrlHandler-ISAPI-4.0_64bit thinking along the lines of the MVC routing - still, I cannot find a solution here either.
I've had a dig through posts on here and asked Google but failed to come up with a solution. Any other ideas?
Related
I am experiencing problem in VS 2022 in Blazor complex project. After moving Blazor components to different namespace/folder the components are not functional any more. My component does not 'recognize' other Blazor components anymore. For example custom component MudTable from MudBlazor namespace:
I would like to be able move Blazor components easily as simple classes.
Sometimes it helps to specify the same namespace in razor file to match namespace in partial code behind class, but sometimes I end up creating component (razor and cs files) with different name (copying the same code). This is very time consuming. I am not able to reproduce the described bug in Simple Projects. I have tried to reproduce the issue but it works fine (with minor VS bug) as described below. I will keep trying to reproduce the issue on Sample project.
Please find below scenarios working fine:
Simple scenario working fine
Steps to reproduce the issue:
Create Blazor Server App
Create folders
Components
Components\Sub1
Components\Sub2
Add new Razor component e.g. MyComponent1.razor to folder Components\Sub1
Verify that <MyComponent1\> works on some page. Eg. add lines to Index.razor:
#using BlazorApp1.Components.Sub1
<MyComponent1 />
Move MyComponent1.razor to folder Components\Sub2
Update Index.razor:
#using BlazorApp1.Components.Sub2
<MyComponent1 />
It works fine
More complex scenario with minor bug
Create Blazor Server App
Create folders
Components
Components\Sub1
Components\Sub2
Add new Razor component e.g. MyComponent1.razor to folder Components\Sub1
Add behind the class to 'MyComponent1.razor.cs' to folder Components\Sub1:
using Microsoft.AspNetCore.Components;
namespace BlazorApp1.Components.Sub1
{
public partial class MyComponent1:ComponentBase
{
}
}
Verify that <MyComponent1\> works on some page. Eg. add lines to Index.razor:
#using BlazorApp1.Components.Sub1
<MyComponent1 />
Rename folder Components\Sub1 to Components\Sub1Renamed.
Visual studio does not display any error and project can be compiled/started. Code behind is even displayed 'linked' to razor file:
This seems as a VS bug to me.
When project is started Component1 is invisible on Index page, because component 'BlazorApp1.Components.Sub1.Component1has no visual code defined, because it has only non-visual definition 'behind the code'. The file 'Component1.razor' with visual is not used at all because it is in unused namespaceBlazorApp1.Components.Sub1Renamed`
Update Index.razor:
#using BlazorApp1.Components.Sub1Renamed
<MyComponent1 />
When project is started, Component1 is visible on Index page (but I assume that no code behind is processed)
Do you have any hint, how to make it work for blazor components ?
I am using Visual Studio 2022 v 17.2.1 to create an ASP.NET Core/6 app.
When I make HTML only changes to my Razor Views, and I try to hot reload the page, I get the following
Here are my Hot-Reload settings
How can I get the Hot-Reload function working so I don't have to restart my app every time I want to see the change in the browser?
One possibility is that you are using Response Compression Middleware (UseResponseCompression()) in the Program.cs file.
It seems that this middleware is no longer needed for Blazor Webassembly, and that for some people removing the installation of the middleware UseResponseCompression() fixes the problem of getting an error when attempting to hot reload. Some Microsoft documentation says to use the compression middleware, but this breaks the hot reload functionality, in my exprience. Once this call is removed, hot reload works for running with the Debugger attached and not attached.
I have an ASP.NET site that I am deploying to Azure Websites. I have a production and staging environment there and it is easy to get lost which is which. During the web deploy ("Publish") from Visual Studio, is there some simple way to deploy some kind of build info that I could display either via the site itself or through the Azure Portal?
You can add a version number to your assembly by adding this line to AssemblyInfo.cs file
[assembly: AssemblyVersion("1.0.*")]
more details here and here
you can then expose it in your site however you want, maybe a hidden tag, some sort of debug info page, or write it to a file on Application_Start that you can look at later
for example in global.asax you can have
protected void Application_Start()
{
using (var writer = new StreamWriter("version.txt")
{
var version = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();
writer.WriteLine(version);
}
}
Generating a text file with current date as a post-build step was the easiest solution I found.
I am trying to enable view compilation to have my ASP.NET MVC3 web site load faster. My web site is hosted on AppHarbor.
However, my views make use of MVC3 view helpers, defined in the App_Code folder.
When I try to load my web-site, I get:
"The directory '/App_Code/' is not allowed because the application is precompiled."
How can I stop the App_Code folder being deployed to the web-server, but still have the App_Code helpers pre-compiled?
I've tried changing the helpers to Content=None, but this leads to an AppHarbor build error because the helper files cannot be found during pre-compilation.
Old question, but I just got that problem, and the following procedure has worked for me:
Go to https://appharbor.com/your-application.
Click on Settings.
Click on Build | DISABLE PRECOMPILATION.
Force appharbor to do a rebuild/redeploy (by pushing a new commit to the repository).
I have just deleted my shared helpers and deleted the App_Code folder because of this problem. I have changed my project to use partial views instead .
According to this answer helpers must be in the App_Code folder but this won't work using AppHarbor.
I would say , don't use App_Code folder in web application. Please find more details ****here****
Running under Server08 | IIS7. I have a website project and am in the habit of hand editing the Global.asax.cs at the deployed site many times in the past. Recently I've found that only the Global.asax is present and has only:
<%# Application Codebehind="Global.asax.cs" Inherits="myDomain.MvcApplication" Language="C#" %>
There are simply no Global.asax.cs files present/visible for any of my active, functioning websites anymore.
I've checked here Global.asax can't find code-behind class and here where is the codes in Global.asax in mvc3? without getting anywhere. The second link contains the comment: 'That's because it's a compiled web application. You'll have to view it in Visual Studio as a project.'
But since my project has always been a website - and I've not converted it (intentionally) I'm puzzled by the changed behavior.
But when i step into VS12 and look at the context menu for the solution's WebProject it presents 'Convert to Web Application'. The sites' folder structures do not contain App_Data or App_Start. To my mind, these 2 fact establish at VS is treating the project as a website, why then, is the Global.cs compiled down to the /bin?
I'll close by repeating - I've hand edited these things in the past - I'm not positive but it's probably accurate to say that this is the first time I've tried to do so after installing VS12. And, coming to think on it harder - it's only recently that I've implemented the 'One Click Publishing' service so that could be coming into play.
verify? I'd like I need to edit a simple update without full re-deployment.
thx
I think the 'One Click Publishing' is most likely the culprit here. I created a sample Web Site project to experiment, and when I use the publish feature in Visual Studio, the files generated are indeed missing the Global.asax.cs file. Instead, a bin folder is created with a compilation called "App_global.asax.dll" even though it is a Web Site and not a Web Application. I am guessing this might be similar to what is happening for you as well.
If not, I found a link which might be useful to you in order to once again be able to edit a class on the server. Particularly, have a look at the second answer (the one not accepted as the best answer) to recreate a class file for the global code: Where is the Global.asax.cs file?
I tried this solution, and verified that the class file is editable on the server, and that it is dynamically compiled at run time (the modifications I made to the file worked immediately).
Hope this helps!
After editing the global.asax you need to rebuild and upload the DLL to the bin folder. Otherwise, your changes will not take effect.
You might be able to upload an web version of the global.asax that includes the code in that one file, which obviously does not require a .cs code behind. I used to do it with aspx files in an application but I have never tried it in the GLobal.asax file.