ASP.NET MVC5 views pre-compilation - c#

I am using ASP.NET MVC5 and Visual Studio 2015 for own web application. My application is deployed on the IIS 8.5 server. I have very slow performance during first loading of the each page. The next each request for the specific page is very fast. I think that this is due to compilation of the page. Please help me, how i can setup pre-compilation of the views during publishing process on the build server?

The question here is, how heavy are you pages, it sounds to me browser caching is making the pages faster on your second call. it dosnt to do anything with IIS. in IIS the first load is always slow once the project gets built the next requests will be quick.
so I suggest look at your view, optimize images and scripts and etc...

We use Razor Generator for this, it's a VS extension.

Related

Azure Web App c# razor new page returns 404 page cannot be found

I have a long running Net 3.1 Web App using c# with Razor. I recently added a new page .cshtml . On localhost, the new page will appear and operate as expected, however after Web Deploy from Visual Studio, xxxxx.azurewebsites.net , the page in question returns 404. There is no subdirectory, its at wwwroot level.
Reviewing errors in logstream in Azure Portal, it shows the file in question and directory path does not exist. xxx.net:80/newpage
Deployment is to Windows based Webapp service.
You're question is a bit vague. I will try to answer as best as I can.
Assuming the web app is setup properly,
When running locally, if you have the .cshtml file open and in focus, (most of the time and if there is no model where the view is expecting data) Visual Studio will render the html in the browser regardless of anything else.
In the cloud, you need a controller action that is the route to your view. If there is no subdirectory, then your Home controller should do.
Another way in the cloud to render the html apart from everything else is to separate the file as an html file and do some routing and DNS configuration.
Please offer some code example of your specific situation and/or what you have tried so far and I will attempt to help further, if I can.

Transparently decomposing an ASP.NET Website hosted in Azure

I maintain a website written in ASP.NET MVC 5, and hosted in Azure. It's a legacy app that is a real nightmare to maintain, and so I've been asked to start migrating to a new codebase and the ASP.NET Core framework.
Our goals are:
Migrate one page at a time
Don't lose the "F5 debugging" experience in Visual Studio
My initial thought was to use a virtual application/directory, which is supported both in Azure and in IIS Express. The idea is to point, for example, the /Shop page to the new website by using a virtual path. Then when we're ready, move the /Team page and so on. I would add a virtual path for each migrated endpoint until the migration is complete.
To accomplish this I created a new ASP.NET Core project, and I've been trying to edit my applicationhost.config file and trying to start multiple projects from Visual Studio, without luck.
I tried configuring two sites with the same port binding, two apps within a <site> tag and also two virtual directories within an <application>, but I always end up with errors. Either I can't start debugging (Can't connect to IIS Express or The object invoked has disconnected from its clients messages) or I get a 502 error.
I don't even know if this is going to work in Azure, but I know we can't go down this path without proper development experience.
Am I missing some other, better solution? If this is a good solution, is there any way to make this work in Visual Studio?
I would consider creating multiple new websites in Azure, one for each section. Then, as I start working with Shop, for example, I'd leave an almost-empty controller in the original solution, redirecting to your new Sales web site. Using this approach, you can efficiently work with one smaller code base at a time and in the future scale the individual pieces of your site as needed. Please note, that you can host multiple sites within the same app service environment (thus not incurring a lot of extra cost by separating into multiple processes).
Best of luck :-)

How to ensure a CSS file is refreshed using ASP.NET MVC5 and IIS 7.5 express

I was trying to refresh the file x.css, which is served via a style bundle in mvc. I must add that the bundle optimizations were disabled for development purposes. I tried updating my web.config, restarting IIS and rebuilding the application. But none of this seemed to work. I also tried disabling caching as suggested in this answer:
ASP.NET MVC how to disable automatic caching option?
But the file would stay unaltered. The server finally refreshed the stylesheet after I reran the application multiple times followed by multiple (and I mean many) broswer refreshs. Why did this happen? Is there a better solution to this problem that does not involve renaming the file?
For bundling, the ?v querystring value will change when you update the file. So make sure your scripts have the ?v=... querystring at the end of them.

Publishing .NET 4.5 ASP.NET website on IIS 7.0 yields an error 404 though the files exist

I am trying to deploy my first ASP.NET application on a server running IIS 7. But I always get an error 404 when trying to open the page. I thought it might be a start page issue, so I entered a direct URL to a .aspx file inside the wwwroot folder, but that got me another 404. Next step was to set a start page in the IIS Manager to a certain .aspx file, which made the page open, but the URL shown didn't include the specific page, and I didn't see my bootstrap navbar (just links that should be inside it) nor my Infragistics components. (To give context, we just upgraded the server to .NET 4.5 this morning, but all other ASP.NET websites in the same or other application pools still work perfectly!).
I then enabled the option to see folder contents in the browser; opening the website then showed me all the files that were supposedly not found, but clicking on them gave me 404 again. For testing purposes I put a .html inside the main folder: that one I could click and open, as well as *.css files or images in subfolders. But as I said above: ASP.NET is installed and working for all the other websites. I checked the MIME things, there is nothing for ASP related files, but neither is there in the working projects. The handler mappings seem to be correct as well.
So what could the reason for this be? I am totally unacquainted with IIS, so I lack any ideas beyond simple googling :/ My guess would be something permission-related (the app pool it's currently in is using pipeline mode: classic; but again, the same as the working stuff) or another dynamic content option I missed. Or - since as soon as I manually define a start page to be one of the .aspx files, I see at least something - it could be related to extensionless URL's? When I manually enter
myservername\myappname\StartPage.aspx
the browser at least shows
myservername\myappname\StartPage
instead. But I can't seem to find an option to change this. Any help is greatly appreciated!
I ran into this issue when I first started working with ASP.NET. I spent hours scratching my head trying to figure out what was the problem. After a fair bit of research this is what solved my problem. I added the flowing code in the web.config file.
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"></modules>
</system.webServer>

Display downtime page when publishing application

Is it possible in ASP.NET MVC to display a downtime page when publishing a project out to a server?
Right now, if I hit the page while I am publishing I get an error:
Could not load type "App.MvcApplication"
It would be awesome if we could setup a downtime page so that users know to come back at a later time, instead of thinking that the app is busted.
You could add an app_offline.htm page to your application root, traffic will be redirected to that page until you remove or rename it.
More info
Scott Gu's App_Offline.htm
App_Offline.htm and working around the "IE Friendly Errors" feature
Will app_offline.htm stop current requests or just new requests?
An alternative to doing this in the application is to have IIS sort this out for you.
Application Initialization Module gives this feature, and also allows you to run warm-up scripts.

Categories

Resources