Deployment to a shared web server causes my relative links to break - asp.net-mvc-3

I'm new to MVC3 and have the feeling this may be an obvious problem but nevertheless I can't find a related question on the issue.
I'm developing a web site in MVC3. My production environment has several web sites positioned as follows, eg:
www.companywebsite.com/app1/
www.companywebsite.com/app2/
...to
www.companywebsite.com/mynewapp/
I'm using IIS on Windows server2008 and have created the "mynewapp" folder. But when I deploy my application into this folder all my relative links and files break.
I've converted my scripts and images to T4-MVC references which seems to handle the relative paths but any bog-standard hyperlinks that I have as relative links will not work (and I don't want to convert them to Razor links due to use of images).
All my mapped routes are working fine without change.
Is there a global setting I can use for deployment to the production environment which will tell my project that the base folder is /mynewapp ??
Thanks in advance.

Related

Orchard CMS can't find scripts or styles

I have prepared an Orchard based website locally, using WebMatrix. I then published to my hosting provider.
However the deployed version isn't picking up the styles or scripts, either my theme or for the dashboard, and it's giving me 404 errors.
I guess I have to change the path somewhere to get it to pick up the files, can anyone tell me where? or is there a different solution?
I thought that this would be a setting on the website, but as it turns out it was an IIS setting.
I switched the pipeline mode from Classic to Integrated, and everything worked.

Best way to share a common CSS and Scripts between web applications?

Using: Dreamweaver CS6, ColdFusion 10, CFBuilder 3 (soon)
I'm currently developing three seperate web projects but am using the same set of resources for each project:
Same CSS reset and initialisation styles e.g grid layouts
Same JQuery initialisation files
At the moment each web project has a copy of the same files in its web root. I'd like to have a place that all the sites link to get these common shared resources. I can only think of two ways to do this, both similar:
Decide on a 'master' site and place all the CSS and JS files in that site only.
Make a new site called 'shared or common' and put all the common stuff in there. but this new site still has to reside on some domain. So I still need to choose a 'master' project.
Both the above points are somewhat difficult to do because there is no 'master' site. None of the sites are linked in any way to each other.
Say I've decided on a master site then I could then link to those files using a fully qualified URL. But this means that when I am in my development environment I won't be able to see these files and use any kind of IDE introspection to see whats in the files when I make changes (e.g. like intellisense detects whats in the files and gives you hints).
Overall whats the best way to share these resources for both development and production environments?
Update: After the answers I realised I need a virtual directory in IIS and also a virtual folder in my Windows 7 local folders where my web project files are kept.
You need to use web server virtual directories (for IIS) or alias (for Apache).
Simply create an alias/virtual directory called 'scripts' (or whatever you want) in the web root of each site (you can do this in your development environment too, if you are using IIS or Apache) and then simply use
<script src="/scripts/my.js" ></script>
I'll venture an answer.
We have shared assets across HTTP to sister sites and some unrelated sites. But the primary site collapsed and it created a single point of failure that cascaded in insane ways across our other sites (support calls were also insane until we got the primary site fixed).
Nightmare. Never again...
What I suggest is to create an Amazon AWS S3 bucket and host your assets there.
Provided you don't exceed 20,000 requests or 15GB of data per month it is free.
There are lots of setup examples on the internet.
AND if I can set this up and get it working like a charm, then you should have no problem either.
Just a consideration...Good luck.
We do this without sites. Instead we use server mappings. In the CFAdmin tool, we have mapped logical path "/" to a directory path. That directory path has folders for js, images, css, and templates. Then if we want to use a javascript file, it's simply:
<script src = "/js/theFileIWant.js">

Visual Studio: Pre-Build add contents of directory to project

I have the following setup:
Main Website - MVC 3 project, to be hosted on www.domain.com
Intranet Web App - MVC 3 project, windows authentication, hosted on admin.domain.com, which is only accessible from within the local subnet.
CDN Website - A simple web app that merely serves images to both of the above. It will be hosted (publically) on cdn.domain.com, when we go live. I have set up a local project to mock the CDN during development.
I've written a business layer that allows users in the admin panel to upload images, which are then physically saved to the CDN path that's configured (currently on the local machine i.e. C:\Code\SolutionName\CDNProject\images). The main website then uses the same business layer to find and distribute the images via http://cdn.domain.com/images/. http://cdn.domain.com is currently set to http://localhost:55555, while we develop.
Whenever an image is created via the admin panel, it is physically created on disk. Each developer works on his own machine, we we want to be able to check these files in to TFS, for the time being. As you might have guessed, adding files to the file system does not automatically reference them in the project:
I thought there may be some way to reference these images as resources, or set a directory to a "content" directory of sorts... but I can't find anything.
Some developers work remotely via VPN, and do not have access to the local network (only TFS), so a network path is not an acceptable solution.
I thought I might be able to set a pre-build event up, to add all files in a directory to the project?
There is no very easy way to do that. There are a few ways to think about:
1) Write VS adding which adds new files to project (via DTE - starting point). Find out how to automatically run this VS addin on Pre-Build step. Install this addin to your developers machines.
2) Extend your admin logic to automatically check-in the uploaded files to TFS via TFS API
3) try to apply more sofisticated techonologies like this one: T4 Tutorial: Integrating Generated Files in Visual Studio Projects
Hope that helps,
Visual Studio project files have an XML syntax. Project file properties can be modified in a simple text editor (files added/removed, etc.).
You can create a script to open your solution, and before actually opening the solution, you can scan that directory and "inject" the files (with the appropriate XML tags) in the project files.
I don't think you can add this as a pre-build event because the project files are already loaded at that point, and you cannot modify them while they're used.

Deploying Asp.net MVC web application

I have been trying to find a neat tutorial, guide or step by step instructions for deploying an Asp.net MVC3 webapp but have found nothing so far. Everyone talks about his version of the stroy and different type of MVC versions.
Right now, I have build a simple Asp.net MVC web application which i need to deploy on my shared hosting account. In a very simple manner, I need to know which files should i copy. Do i upload everything in my webproject directory to the server including the controller directory, views, models, content and bin directory ?. What about the Global.asax, web.config, packages.config, myapp.publish.xml.
In short, I have no idea which files should be uploaded and which should be not. I am sure of one thing that i need few(MVC and Razor dlls) following dlls in bin directory. Just treat me as someone who has never deployed any website
NOTE:- I don't have VS SP1 installed and it doesn't install either. Basically i need a manual procedure.
Here is a tutorial on the MSDN site about how to deploy an MVC application. Typically, hosts will also now have WebDeploy available, which is a very easy way to deploy and update your application without having to worry about what files to copy.

Visual studio 2010 Publish / web deploy issues

I'm using Publish/Web Deploy to deploy an asp.net aplication from Visual studio 2010. It works perfect, but there is a problem. If the new release is not working as expected, the old version is already replaced by the new one and there is no easy way to roll back to the working version. How is this best solved? I wish it was possible to keep the old version on the server so I could just switch back if needed.
With WebDeploy there is no built in rollback feature, so once you've deployed that's it.
There's a number of hand rolled strategies you could put in place, for example:
Limited Access e.g. Shared Hosting:
Where you don't have full access to the machine -
Backup the live site beforehand by downloading it.
Keep copies of what you deployed so you can push the previous version should something break
Full Access:
Maintain two sets of folders for the application and map your site to one or other of these folders. When you come to deploy switch the IIS site's physical path to the other folder then deploy. If the site fails then just knock the site back to the original folder. Each successful deploy would alternate between these two folders.
For stuff like user uploaded content you'd need to map virtual directories to a place on the file system that's always the same place because you don't want to be copying these around each time.
You're not the only one who has encountered these issues. Have a look at this article by Rob Conery and his observations about the state of affairs regarding ASP.NET deployment.
ASP.NET Deployment Needs To Be Fixed
Getting Constructive On ASP.NET Deployment
Using some form of Source Control would be another alternative. We use subversion, so if the publish goes bad, we can just update back to the last-good revision, and publish that. Even if you're the only developer, using source control can be very useful.

Resources