I am new to MVC and want to migrate a Asp.net web application in MVC.
But i am stuck on how to deploy my web application on server IIS by copying all the source files on server (Xcopy deployment).
As in Asp.Net web application you can just create any new page and copy paste it on your webserver, it automatically gets compile and executed when browsed. Can this be done for MVC application??
I have even observed that when i host my MVC web application in IIS then any change in Views get reflected correctly without compiling the project , but i have to compile the project to make changes of controllers and models.
While you can add the App_Code directory to your asp.net MVC project by right-clicking on your project, as shown in the picture below, and put code in it that recompiles on the fly when it changes, in my opinion that's not a good solution. I will follow up the App_Code explanation with what I think you should do.
Clicking on the App_Code option will add that folder to your asp.net MVC project. Once you do that, you can add a class like the following to that folder:
public class TestClass
{
public string Description { get { return "Stuff"; } }
}
Then, in a view, you can create an instance of that class (which will be in the App_Code namespace by default, and reference the Description property like this:
#{
ViewBag.Title = "My View";
var test = new WebApplicationMVC.App_Code.TestClass();
}
<h2>#ViewBag.Title.</h2>
<h3>#ViewBag.Message</h3>
<h4>#test.Description</h4>
When you change the Description property's implementation, the site will recompile and use the new code. You could, for instance, change Description to return "More Stuff". In my opinion, recompiling like this on the fly is a bad solution. IIS handles site updates pretty well by overlapping the recycling anyway.
A better solution is to use the deployment wizard. The deployment wizard can deploy to your web server, Windows Azure, FTP, or local file system. And, the cool part about using the deployment wizard is that you won't end up uploading all of your source code to the server - it only copies what you need in order to run your site. To run the deployment wizard, right-click on your project and click the Publish option.
Once you are inside the deployment wizard, I recommend choosing Custom and then using the local file system option. Once you choose the local file system deployment option, you'll get the Settings tab where you can select Release or Debug (Release is recommended for production). Under "File Publish Options", I like to select the "Delete" option to remove all files from the deployment directory before copying new ones. Here is what the deployment wizard looks like:
This method of deployment does not allow you to deploy ad-hoc changes to controllers, models, etc; however, it is very clean and the proper way to deploy your site in my opinion.
You only need to copy from the deployment folder the files that you need to change. For example, if you just updated a view, you can copy just that view and the site will recompile that (as you've discovered). On the other hand, if you've changed something in a controller, copy the main assembly for your site, which is the dll, usually having the same name as your site, in the bin directory of the deployment folder.
Related
I have tried these steps but could not make it. When I browse my app it shows dll file.
Log onto the machine that is or will be hosting your application.
Use IIS Manager to create a new website for your application.
Create a new application in that site. I believe this also will automatically create an application pool with the same name for you and use it by default.
Specify the virtual directory for your application. This is going to tell IIS where to look for your mvc application. For this case lets assume it is C:\myApp
On your own machine Build the application however you build it with the correct solution configuration (i.e. Release mode). Lets say the result of your build is located at C:\MyProject\bin.
Copy C:\MyProject\bin from your machine onto your hosting machine at C:\myApp
I am a novice to this technology.
you shouldn't just drag the bin folder. it is everything else too like the images, css, jscript files as well as the cshtml files too (your views) to the c:\myapp folder.
or perhaps just do a publish within visual studio. maybe even take a look at this to see if this helps:
How to publish my MVC 3 web application onto IIS7
but generally speaking, I build the solution. I then create the vdir in my IIS. I copy the bin and view folder along with images/css/jscript/shared folders etc... to C:\my deployed site. I then convert to application for that vdir I just created in IIS.
You have to use publish action for ASP.Net web application(MVC, Forms and etc.)
ok, i know there are a lot of posts online that specify how to do iterations with MVC.
my question is slightly different. when i used to do iterations using WebForms, i was creating one thing only and finishing that one thing till the end which was including the deployment on production.
for example, i was creating a webpage and deploying it, then i create the second page and deploy it. so .dll files were added to my bin folder while the previous dlls remain untouched. at the other hand, when i was making a change latter on, there was this one file that needed to be replaced on production.
now here is the question, how can i acheive the same thing in mvc? beause it just doesn't deploy each page into an individual dll. each time that i add something i have to redeploy the application dll which is not really wise! i played around with deployment options in visual studio but no luck!
There is nothing preventing you from putting controllers and other code in separate assemblies and dropping them in an existing application. Like any ASP.NET based application an MVC application will automatically restart if you add or modify any file in the bin folder or modify web.config.
If you're using Razor you can use RazorGenerator to generate code for your views and compile them into the same assembly.
You may need to write some additional logic though to get routes, model binders etc. wired up correctly.
For a more structures approach to compose the application of separate modules, you may want to look into portable areas. This is an extension to ASP.NET MVC that allows you to package the entire module (including views, css, js etc.) into a single assembly.
First thing, you have to work on the title of the post, it does not match the content of the post.
In asp.net mvc u can choose to deploy only what changed. I.e. If you only changed the .cshtml file, then you can just replace it with the file in production. However if you change any controller class (C#/Vb code), then you will have to upload the web project dll file too so that this new changes are available in the production env
My MVC .net Solution has 2 projects:
The actual web project
This is all my models, views, controllers, attributes, etc. Some of the controllers reference my Reporting project, which includes local (e.g. non-server reports) reports that use SSRS and PDF generation.
The Reporting Project
This includes code that will connect to a database and generate the reports. The project also includes a folder that has a bunch of report templates. The report templates are "embedded resources". I have confirmed that they show up in the bin folder of the MVC app when I deploy.
The problem is, when I call the reporting code from within a controller, IIS looks for the report file relative to IIS. In the report code, I might say to look at "report/confirmation.rdlc". This works fine in a console app, however once I deploy with IIS, that path ends up being "C:/program files(x86)/iis express/reports/confirmation.rdlc", which does not exist.
I have also tried "~/report/confirmation.rdlc" to the same result.
I am assuming this means that the home folder (~) is in fact the IIS Express root. How can I change that for the app?
Just try to use Server.MapPath("~/bin/reports/confirmation.rdlc") instead.
I have an MVC 3 app that has some core functionality (most important is autorisation) but mainly serves as a portal to different areas or modules. I want to organize thit to different modules that with minor changes also can be deployed as their own website.
The project consists of a Forum, Blog engine, Messaging between users + 4-5 upcoming modules.
I looked at ScottGu's blog about MVC 2 and found something that seemed perfect:
Depending og what the customer need I want to only give them the exact modules they can use. It is also easier from a maintainence view to be able to work and update referencd assemblies in each project and just do a full update for the customers that have that spesific module on their server.
But in MVC 3 there is no apparent way to use Areas this way, do you know how?
Status
I will try to add MVCContrib Portable areas to my existing solution and convert my areas ower and will post back the results. If it works I will mark it as the accepted solution.
MVCContrib has portable areas.
http://mvccontrib.codeplex.com/wikipage?title=Creating%20a%20Portable%20Area&referringTitle=Documentation
This is possible in MVC3:
From:
http://bob.archer.net/content/aspnet-mvc3-areas-separate-projects
Right click on the shell project and "Add Area...". Type in the area name. This will create an Areas folder with your area in it. (This is not 100% needed but you do need the "Areas" folder and you can steal the XXXXAreaRegistration class for your application.)
Create a new MVC3 empty project in your solution to match your area. Move the XXXXAreaRegistration.cs file from the shell mvc project to the new project and adjust the namespace as applicable. (Or you can manually create an area registration class, it's a pretty simple class. Just use the Add area template generated one as an example.)
Edit the routes in the AreaRegistration folder as needed.
Delete the folder under the areas folder that the template wizard added.
Modify the web.config of the new project and take out the connection strings and the authentication, membership, profile, rolemanger sections. You will not need to deploy this web.config but the razor intellisense doesn't work without it during dev time.
Delete the global.asax file from the area's project or you will get extra default routes.
Create a virtual directory in the "Areas" folder of the shell project with the name of your area as the alias and point it to your "area" project. You will need to use IIS or IIS Express for this. I use IIS. For IIS Express you can use the appcmd.exe in the IIS Express folder or you can edit the applciationhost.config file.
Can we deploy an asp.net MVC application by copying the source codes only (without compiling them first) like we can do when deploying WebForm website project?
No - MVC apps need compilation, like ASP.NET Web Application Projects.
Wait... if what you mean is copying the *.aspx and *.ascx files, yes you can, but you have to include the *.dll in the bin folder too.
Copying the *.cs files is useless.
Start by building your application, then select the project (not the solution) that is your StartUp project (the one with the aspx files), then, in the main menu, do Build > Publish Selection and follow the wizard.
I'm afraid the answer that has been marked as correct is incorrect.
You can have your controllers inside your App_Code folder. You should follow the naming conventions for your views' folders (~\Views{ControllerName}{ViewName}.cshtml), and simply ensure that your route map correctly wires up the controller. If you do create your controller using the default App_Code behavior, it will not be placed inside a namespace. You should either wrap it in a default namespace ({SiteName}.Controllers) or explicitly set the namespaces: argument to include an empty string for the namespace.
Only if the code you are talking about reside in the aspx/ascx files. Most of your code should reside in your middle tier/controller/data tier - so having too much code in the views is usually considered as a bad practice in logic/concern separation.