Display a custom html page when publishing to IIS in MVC - asp.net

I have an MVC5 application and I want to display an html (or htm) page while publishing the application to IIS server. So, I tried different methods by using app_offline.htm as indicated on ASP.NET Web Deployment using Visual Studio: Deploying a Code Update. But none of them works properly in MVC. Is there a better approach to make this?

Seems like app_offline.html customization not supported yet. See https://github.com/aspnet/Tooling/issues/530.
Also, there is similar question Custom app_offline.htm file during publish.

Related

I'm having trouble understanding exactly what ASP is and how to upload an ASP website

As of the start of this week I've been required to start learning how to develop websites in ASP. I have a moderate level of experience with C# through XNA, so that part of it isn't much trouble for me.
I've been following a Music Store Tutorial which takes me though setting up an "ASP.NET MVC 3" application.
I'm about done with the tutorial and have a functioning site when I run a test locally, but I don't understand what files need to be uploaded. I've worked on front-end updates for ASP websites before but they were completely different to this in terms of what files made up the site and so on.
I don't see a single .aspx page in my project which is what I assumed an ASP site was made of from experience. I'm starting to think that those projects weren't MVC projects but maybe just the "ASP.NET Web Application" style project.
Are ASP.NET and ASP.NET MVC different? From what I vaguely understand, MVC is just a framework that wraps ASP.NET? Also, is ASP something or is that just a synonym for ASP.NET? Finally back to my initial confusion, what files are to be uploaded onto the server when I want to launch an ASP.NET MVC project?
Do I just upload this entire directory and the server will handle it in the same way that the inbuilt testing ASP server does? Or is the site compiled down into a couple of files somehow and I just upload one of these directories (I think I read that somewhere).
ASP is an acronym for Active Server Pages. Pre .NET, ASP was Microsoft's first iteration scripted web pages. All of those pages typically ended with the extension .ASP.
When .NET was released, ASP was overhauled significantly and renamed ASP.NET. The new version of ASP.NET attempted to model web development similar to windows application development, where you used controls and an event handling model. That was Microsoft's primary model for web page development for many years, and it still around and supported, but today it is referred to as ASP.NET Web Forms. ASP.NET Web Forms pages typically have the .ASPX extension you mentioned.
In the mid-2000s or so, Ruby on Rails took off, using an MVC based model for developing web applications. A few years later, Microsoft released an alternate version of ASP.NET, called ASP.NET MVC, which used similar concepts. Many people feel the MVC approach is a more natural method for developing web pages than the web forms model (note epic Q/A threads on this very site a few years ago). In any case, ASP.NET MVC shares parts with ASP.NET Web Forms, but looks and works pretty differently; for one thing, there are no .ASPX pages as MVC, for the most part, uses a different form of routing to determine what to display.
That's a very brief history that glosses over a whole lot of subjects. What you've posted a screenshot of, is an ASP.NET MVC project.
As far as publishing is concerned, the typical route for publishing an ASP.NET website is to open the project in Visual Studio, select Build|Publish, and tell VS where to put it. Depending on what method you use, you may have to do additional configuration in IIS on the box where you published the site.
First off, when you say ASP, you're referring to old (obsolete) tech. ASP.NET is specifically what you're referring to in your question.
ASP.NET is a Microsoft technology which works cooperatively with the IIS server to provide a "Windows Application" type experience with web sites. Your web site logic is compiled in to a .NET DLL "Class Library." When a web request hits IIS with a URL matching your application directory, IIS starts up your application internally and maintains it.
I don't understand what files need to be uploaded
Visual Studio actually has a built in publisher available for your use. See the Build -> Publish menu in VS / Web Developer.
I don't see a single .aspx page in my project which is what I assumed an ASP site was made of from experience.
ASP.NET Web Forms uses the aspx extension for Pages, their frontend rendering component. On the other hand, ASP.NET MVC uses the concept of Views, which are not relient on a specific component. See the next paragraph.
Are ASP.NET and ASP.NET MVC different?
Yes. No. Maybe. ASP.NET contains all the "magic" which allows IIS - the web server - run the web application and serve up web pages. Volumes could (and have) been written on this. ASP.NET also supports much configuration through the means of Http Modules and Providers. These components are declared and configured through the web apps web.config file and are typically automagically created and persisted by IIS and ASP.NET. They collectively make up the glue that makes ASP.NET just work out of the box.
MVC was built on top of the existing foundation classes of ASP.NET. Some features have been loaned, a few have been replaced and more than a handful have been created in order to support the model-view-controller pattern.
For example, MVC gives us support for View Engines - a runtime library which allows us to write our Views (web pages) in a particular format. The ASPX View Engine existed during MVC's launch. Later came Razor, employing the .cshtml extension. Users of the MVC Framework have implemented a wide variety of their own view engines as well. This is possible due to the modular nature of ASP.NET and MVC.
Do I just upload this entire directory and the server will handle it in the same way that the inbuilt testing ASP server does? Or is the site compiled down into a couple of files somehow and I just upload one of these directories (I think I read that somewhere).
I would recommend using the Build -> Publish menu in Visual Studio. You may use web deploy if your host supports it, but FTP and File System methods are available as well.
The bin folder contains the class libraries required to run your web application on the server. The web.config file provides the configuration to do so. However your Views are not compiled in to the assembly. They are published as-is and are rendered lazily by the view engine.
You are probably familiar with ASP.NET WebForms, this is an MVC project. You can find more here:
ASP.NET MVC
In order to upload the site, you need to publish the website from inside Visual Studio to a local file location and then upload everything to the website.
If the target server doesn't have MVC installed, you can right click on the website project in Visual Studio and select "Add Deployable Dependencies".
This will ensure that the server has all the required files to run an MVC project.

Visual Studio 2010: convert website project to web application project?

I have an existing solution in VS2010. When I click the properties of my project I get the view as can be seen in image1.png:
When I create a new empty ASP.NET web application and click the properties of my project I get the view as can be seen in image2.png:
A huge difference.
Now I'm implementing this code here: http://wcf.codeplex.com/wikipage?title=Getting%20started:%20Building%20a%20simple%20web%20api
And that tutorial assumes I get a view as I've shown you in image2.png
In image1 and image2 I've also marked the menu items: "Website" and "Project"
This makes me assume that I've created a website application whereas I need something different (I'm thinking a web application project).
Not sure what to do now, I need to convert my current application to another thing, but to which type and how to do it?
I also came accoss this post: http://blogs.msdn.com/b/webdevtools/archive/2009/10/29/converting-a-web-site-project-to-a-web-application-project.aspx
But before I start screwing up everything :P Is that what would solve my problem?
It should be possible to use either a web site or a web application project. In the example on the link you've posted, they use the predefined template for ASP.Net MVC Web Applications. This has several advantages - it sets up the structure and other resources for you - it's effectively a template.
For the purposes of the tutorial, why don't you just set up an application that way? If you've already written some code, you can just import it into the new application.
For future projects, you might want to consider which is best for your needs. Apart from structure, there are some other key differences between a web application and a web site project.
MSDN handily provides the differences here:
http://msdn.microsoft.com/en-us/library/dd547590.aspx
If you find you want the features of the web application, then the link you've posted is fine. You'll need to do some re-organizing of your references and so on and so forth, but the process is fairly straightforward (but not painless).
A "web site" in visual studio is the old, .net 1 style of creating web sites. It basically dynamically compiles the code in a folder when it's hit for the first time. Later .NET introduced a "web application" model where the code is compiled into a DLL and no code files are deployed with the site. "Web sites" are pretty much depcrated and shouldn't be used for any new projects unless you're doing a quick demo site.
The codeplex project you referenced also depends on MVC 3 (which are web applications).
You are probably better off just restarting like the tutorial says - create a new MVC application like it shows in its first screenshot.
If you do not have that option, use Web Platform Installer to add MVC for you - http://www.microsoft.com/web/downloads/platform.aspx
Good luck!
I can't tell exactly what's going on from your screenshots, but if you have a web site that you need to convert to a web application project, you can find the directions here
Although the instructions are specific to VS2005, they are basically the same for 2010 as well.

Why my uploaded pages are not shown on the browsers?

I create a web site via Visual Studio Web Developer. The exension of files are .aspx.
I had also uploaded those files to the hosting server by filezilla client. bt I can't show my pages on the net. Why?
If I write, ../default.aspx, then I meet empty white page include NOTHING.
When I see it on m local computer, there is no any prolem.
Please reply to me as fast as you can.
Best regards, Veli
You will need to "publish" the site using the features in visual studio. This will compile all of your code into the appropriate dll which u will need to upload along with the aspx files
This depends on whether you app is a web site project, or a web application. If it's a web application you'll have to build the site and publish it to your web host. If it's a web site project, you can simply copy the markup and the corresponding code-behinds up.
For more information regarding web deployment of asp.net projects you need to watch the "Web Deployment" section here. It probably will answer many questions you might have regarding this.
Building Applications with ASP.NET 4 WebForms

Debug .asp pages with visual studio 2005

I'm migrating a website made in classic asp to asp.net, but the asp.net dev server doesn't handle .asp pages.
Is it possible to make it run .asp pages? Maybe a custom httphandler for .asp?
thanks!
Are you running Winxp with IIS installed? If so, here's what I do: hit the asp pages in the browser using your local IIS, and then open the folder where the ASP pages reside as a website project in VS. Go to the Debug menu, choose Attach to Process, and then look for the dllhost.exe process that is running under the IWAM_MACHINENAME user. You also have to make sure the you have setup the virtual directory to allow ASP server-side debugging. After attaching to that process, you can set breakpoints, etc. as usual.
The last time I had to debug asp pages I found it was easier to insert a bunch of Response.Write()'s. If you cant find a way to do it in VS, then this may help.
Unfortunately you will have to use traditional (or arcane!) methods to debug your asp pages in VS2005 (i.e. alert(), response.write() etc.)
Possibly not what you want to hear, but vs2005 doesn't support this. It was re-added into vs2008. Perhaps one of the free vs2008 express edtions might get you out of this hole?
In addition to the answer provided by patmortech I would recommend that if you are testing a mixed tech site you attach to aspnet_wp to debug the .NET portions of the app. This is also true if your app uses third-party ISAPI filters.
The Cassini server is good for pure .NET only.

ASP.net: Website or web application project

Is there any difference between website and web application project? What if you are working on a project that is sort of hybrid of site and application? which project should you chose?
I'ld go the newer Web Application project (always, regardless of the size of the project).
There is nothing to lose and everything to gain with using the Web Application Project (you cannot say this about using the "website" only).
The official list of differences are here:
Use Web Application Projects when you
Need to migrate large Visual Studio.NET 2003 applications
Need to
control names of output assemblies
Need stand-alone classes to
reference page and user control
classes
Need to build a Web
application using multiple Web
projects
Need to add pre-build and
post-build steps during compilation
Use Websites if you:
Need to generate one assembly for each page.
Prefer single-page code model to code-behind model.
Prefer dynamic compilation and working on pages without building entire site on each page view (that is, save file and then simply refresh the page in the browser).
Want to open and edit any directory as a Web project without creating a project file
#Mehrdad's link here is essential if you want to know more http://msdn.microsoft.com/en-us/library/aa730880(VS.80).aspx#wapp_topic5
As for which project to choose, I would go with the Web Application Project, regardless of size. Having all of your code behind compile down into a single DLL is a major benefit for maintenance and security on the hosting end. I know there are precompile options for web site projects, but they seemed like more trouble that it was worth for me.
I know that the IIS filters are in place to prevent users from accessing your .vb or .cs files, but it still makes me a little leery.
But more important to this is the nice fact that if you make a bunch of coding changes, or maybe add some classes and change the processing logic, the only thing you have to merge up is the compiled DLL and nothing else. Similarly, if you do a few UI changes (say change the stylesheet or position of a few controls), you don't have to worry about recompiling the application, you simply bring over the update .aspx page and you're done.
Take a look:
http://msdn.microsoft.com/en-us/library/aa730880(VS.80).aspx#wapp_topic5
http://forums.asp.net/p/1300026/2538628.aspx
I'm used to create websites when I want to create a new webapplication.
My current project had some problems on compiling, so I switched to a webapplication project. The step isn't very hard. Visual Studio helps you to change all necessary lines.
Refer to the links in the post:
http://www.codersbarn.com/post/2008/06/01/ASPNET-Web-Site-versus-Web-Application-Project.aspx
Anthony :-)

Resources