Serving ASPX pages from outside the web root - asp.net

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.

Related

How to setup error page handling for subdomains?

On my hosting server I want to achieve the following arhitecture of main site and subdomains:
www.site.com
subdomain1.site.com
subdomain2.site.com
All three domain have some common resources: scripts, css files, images and custom error files to present errors like 404, 503 in a creative intriguing and most entertaining way.
I have organized folders on my hosting server into this structure
www-main
www-subdomain1
www-subdomain2
shared-css
shared-errors
I have setup each subdomain as an asp.net applicatin which resides in its physical folder.
To access common shared resources I have created virtual folders for each subdomain that point to the sam physical folders.
virtual folder shared-css in subdomain1 points to shared-css physical folder
virtual folder shared-css in subdomain2 points to shared-css physical folder
This works ok. But not for folder containing error files. I have configured my web.config and files according to http://benfoster.io/blog/aspnet-mvc-custom-error-pages
The problem is that it does not work for subdomains. If I configure virtual folder as asp.net application it complains it cannot load assemblies for the application for which this folder was created. On the other hand if I configure it as ASp folder it simply does not work.
This same concept works if site is not divided into subdomains but into subfolders instead of subdomains.
Does anybody has a working solution for this problem?
Not suggestions, I have tried many things, anything I could think of.

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?

Determining the Temporary ASP.Net files folder location for a specific site

I have a server with dozens of web sites running on it, and I'm experiencing bad caching behavior on a few of them. I would like to delete the .COMPILED files that ASP.Net caches for them, but I am unable to determine the specific cache folder for a specific site. Underneath the Temporary ASP.Net files folder location are series of folders with arbitrary names (looks like parts of a GUID).
Is there a way to figure out which folder ASP.Net is using to cache files for a specific site?
You can use HttpRuntime.CodegenDir property.
It will return path like:
C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\website1\c2a2b44f\ce865b50
For more reference take a look at msdn site.

Setup IIS 6 to only server static files from virtual directories

We're having the same setup and receiving the same problem as:
IIS 6 with wildcard mapping and UNC virtual directory problem
Setup
Server 2003 32bit, IIS 6
ASP.NET wild card mapping
A virtual directory mapped to an UNC share serving static images for a CMS in a load balancing environment
My question if it's possible to turn off asp.net from virtual and only serve static files e.g. images in the virtual directory, to avoid the problem with too many open connections?
If it's not possible I'll guess I have to implement a solution like Version control of uploaded images to file system to server the files from a local disc.
I found a possible solution at http://blog.stevensanderson.com/2008/07/07/overriding-iis6-wildcard-maps-on-individual-directories/ that removes the wild card mapping and makes it possible to turn of execution of asp.net files.
There is not a way to remove .NET from a subdirectory as it is part of an application at this point (your root directory). However, this method works just fine for keeping .NET from processing your static content.
From your site that you linked:
Alternative
If you don’t like to use adsutil.vbs, you can achieve the same by exploiting what appears to be a bug in IIS Manager. Turn your subdirectory into an application (from its Directory tab, click “Create”). Then edit its script mappings to remove aspnet_isapi.dll. Then go back and “Remove” the application you just created. The metabase’s new ScriptMaps value will be retained, even though the option has now disappeared from the GUI.

ASP.NET Serving Word Documents

I have an application that has a subfolder called "Docs" (actually a virtual directory) where I keep all of my word documents. I don't want these documents to be accessed by any unauthenticated users but for some reason regardless of what I put in my root web.config or my "Docs" web.config IIS still serves the word up to any user.
I assume the files in that folder are .doc
Unless you have modified your IIS configuration, .doc files are not handled by ASP.NET (they should by default be handled by the straight IIS file handler). That means the asp.net dll never sees the request, and so any settings in ASP.NET's web.config file are meaningless.
You would need to configure IIS to identify .doc files as being handled by the ASP.NET dll, or use a wildcard mapping so that all files on your server go through ASP.NET (keep in mind that this adds overhead to have every single static file request go through a full server side programming framework)
Your virtual directory is a separate app that might not be governed by the root. Add the web.config and mappings to the virtual directory.
If this is just a personal thing (your question reads two ways), I would just use an IIS-level password on the folder by removing anonomous access.

Resources