ASP.NEt 4 fixing application path - asp.net

In my ASP.NET 4 website most of source paths/references look like ~/Controls/etc..
When I transfer site to server ~/ starts to point to the root of my domain rather then to the folder where site is located hence all those paths become invalid.
How to fix this in one go without fixing references one by one?
is there something in web.config where I can set application path?

The ~ character is used to base paths from the application root, in this case, the root of your domain. What you can do, in IIS, is convert the subfolder to an application (essentially an application within an application), and this will force ASP.NET to use your subfolder as the root of the application.

Related

Can create site pointing to a physical folder which is sub-folder of another site?

I have two ASP.NET web forms application and I need to run them independently of each other. But for logistical reason of maintenance I prefer to have one as a Sub-folder of the other. Example:
c:\inetpub\wwwroot\MyAppl1
c:\inetpub\wwwroot\MyAppl1\MyAppl2
Each application has its own Form Authentication (different name log in pages)
First I create the MyAppl1 as web site and MyAppl2 as virtual directory. But then running a page in the MyAppl2 gives error:
The virtual path '/Site.Master' maps to another application, which is not allowed.
The above Site.Master is in c:\inetpub\wwwroot\MyAppl1\MyAppl2
Now I am thinking that maybe virtual directory was not the best approach. Can I create MyAppl2 in IIS as a separate Site pointing to a physical directory which is in sub-directory of another site?

Serving ASPX pages from outside the web root

Currently working on an internationalization project. One of the requirements is to take static files published from a content management system and serve the correct language version based on the locale. Unfortunately the published files are .aspx and include references to master pages and potentially other controls.
If the pages are inside the web root, this is pretty easy. I just have something in global Application_BeginRequest that takes a request for /abc.aspx and rewrites it to /content/[locale]/abc.aspx.
For ease of deployment and a couple of other reasons, I would really like these files to be outside the web root. e.g. site is in "D:\www_root\site\" and content is in "D:\content".
Is there a way to achieve this?
You can create a virtual directory in IIS that points to d:\content.
A virtual directory is a directory name (also referred to as path) that you specify in IIS and map to a physical directory on a local or remote server. The directory name then becomes part of the application's URL, and users can request the URL from a browser to access content in the physical directory, such as a Web page or a list of additional directories and files.

create a web site using Microsoft.Web.Administration.ServerManager.Sites.Add

I want to create a web site in my setup project using Microsoft.Web.Administration.ServerManager.Sites.Add method, but it needs a physical path of the web site to be specified. I want the web site to be created at it's default location. How can I find out the physical path of the default location?
Typically when adding a new site this would have a different directory to any pre-existing site. For example IIS comes preconfigured with "Default Web Site" site and the physical path for this typically points to:
%SystemDrive%\inetpub\wwwroot
You would not normally create a second site that also points to that directory. As an example you might configure the second site to point to (or any other preferred location):
%SystemDrive%\inetpub\wwwroot_secondsite\
That said, if you really want to have multiple sites with the same physical path then you should be able to use Microsoft.Web.Administration.ServerManager.Sites property to enumerate all current sites and from there extract the physical path.

why it is still necessary to create virtual directory in IIS when website content is placed in IIS root directory

As virutal directory points to physical path of the application, so if the IIS root directory is C:\inetpub\wwwroot and the application is stored at D:\websites, than we need to create a virtual directory but if the application content is placed at C:\inetpub\wwwroot, then why still need to create virtual directory.
Actually you don't need to create a virtual directory. What you need to do is define it as an application folder, adding a virtual directory does this by default so that's why it works. All you really need to do is right click the folder under your website, click properties and under the Application Settings section click create. Your folder will then have a gear icon off to the side denoting it as an application folder.
As to why application folders are necessary, I believe it's a way of forcing you to choose which Application Pool you want the application running in rather than having every sub directory application running off the same pool by default.
IIS isn't used just for ASP.Net, it can serve up PHP for example...so the type of application and pool varies, it's not automatically created and tied to then ASP.Net engine.
If you can clarify a bit more what you're trying to do maybe we can help further. For example, if you want to point the root application to another folder and it be an application or create another website, IIS allows you to do any of that...you just need to update the question with which version of IIS, as the instructions very between them.
If the IIS site will host a single ASP.NET application you can place it at the root (C:\inetpub\wwwroot) and you don't need to create a virtual directory because when you create the site it is already a virtual directory.

global.asa where does it belong?

I'm moving some ASP code from one server to another. The location names are slightly different and I suspect that now the "global.asa" isn't getting called properly. The location is in c:\Inetpub\wwwroot\myApp.
It belongs in the root folder of your application. Also make sure that that folder is a application in the IIS manager. There is a textbox for application name, and right next to it a button "Create", if the folder isn't already an application.
Make sure that "myApp" in IIS is defined as an application. I would also check the .Net application mappings to make sure .Net is handling your requests.
The global.asa should be in the root of your virtual directory. Note that global.asa is used by asp not asp.net.
You can generally tell by looking at IIS Manager whether or not your directory is a virtual directory as it will not look like a yellow folder. If it does look like the typical yellow folder, right click the parent "Default Web Site" or whatever, and choose new virtual directory.
Alternatively, the global.asa can go in the root of the Web. Which is typically C:\inetpub\wwwroot if you are using the "Default Web Site"
For convenience, I want to keep in a subdirectory. Apparently, you have to designate that directory as an application. Here's a link that describes how:
http://www.calcaria.net/ASP/2006/04/globalasa-file-doesnt-work.html
Generally, I'm against the idea of files which are called auto-magically and not referred to in the code. If you are a noob like me, you can go off the rails for a while, before you track it down. I just lost a couple of hours on this silliness.

Resources