I have a front end application and an admin application in a dedicated windows server on IIS. The admin has an images virtual directory pointing to the front end images directory so that any images uploaded through the admin uploads to the front end directory. Also the admin is a sub domain of the front end website. I am trying to replicate this structure in Azure.
So far what I've tried:
Created two different web apps and mapped the external domains say, www.contoso.com and admin.contoso.com with no problem. But if I need to create a virtual directory in the admin web app, it doesn't allow me to reference anything outside the site\wwwroot folder of the admin web app.
Created two directories in the same web app but cant find a way to map www.contoso.com and admin.contoso.com to two different directories in the same web app.
Uploaded the front end to the site\wwwroot and created a sub directory called admin and mapped www.contoso.com and admin.contoso.com to the same web app and used url rewriting to point the admin sub directory to admin.contoso.com. But still can't find a proper way to add a virtual directory in the admin to point to the front end.
I am using the new portal and the applications use ASP.NET MVC, .NET 4.5 by the way.
Can anyone please point me in the right direction of how to manage and configure multiple websites with subdomains and virtual directories?
Try this - in your 1st configuration. Go to Azure Web apps settings -> Application Settings -> Virtual Applications and directories and setup the physical path of the new folder(Other than the site/wwwroot). Also check the Application checkbox and restart the website once.
I've used the third approach from my question where I created a sub directory for the admin. I would still like to know how this can be done using other approaches.
So I had created a virtual application for the admin already which is mapped to the subdomain. I was trying to add a virtual directory for admin/content/images/frontend to point to the front end site\wwwroot\content\images. I was doing this in one single line of virtual directory setting which was complaining that the path was invalid. So I had to create a virtual directory for each admin/content mapped to site\wwwroot\admin\content, admin/content/images mapped to site\wwwroot\admin\content\images and then finally admin/content/images/frontend mapped to site\wwwroot\content\images which worked.
Related
I have a shared path \\mynetworkshare\myfolder which has images stored.
I have a domain user mydomainuser which was granted with read access to files in that path
I hosted website on IIS. I created a Virtual Directory within my IIS Site with an Alias myphotos pointing to the Physical path \\mynetworkshare\myfolder. I have also clicked on Connect as... button in the Add Virtual Directory dialog box and provided my mydomainuser credentials.
I clicked on the newly created virtual director myphotos and click on Content View in the right pane. I'm able to view all my photos within IIS. From this, I assume the setup of virtual directory to my shared drive is correct.
Now, the question is how do I access this Virtual Directory or Files in it from my code?
I have tried below
var filePath = Server.MapPath("~/myphotos/" + "myimage.jpg");
When I write the filePath to a log file, I see it is trying to map to a physical folder setup within my website folders.
Instead of pointing to
\\mynetworkshare\myfolder\myimage.jpg
it is pointing to
d:\wwwroot\inetpub\mywebsitefolder\myphotos\myimage.jpg
I know Server.MapPath resolves to a physical path of hosted site but I wonder if it behaves the same with my virtual directory.
Or Do I need to let ASP.Net know somehow that myphotos is a virtual directory created on IIS? Or Am I on the wrong path to get files? Do I need to write code something different?
You can get the physical path from IIS (7+) using System.Web.Administration (available in NuGet)
var physicalPath = new Microsoft.Web.Administration.ServerManager()
.Sites["Default Web Site"]
.Applications["/MyApplication"]
.VirtualDirectories["/MyVirtualPath"]
.PhysicalPath;
If the virtual directory is in the root, the Application is "/"
What's specified in the Connect as... may only apply to direct web requests. To access the files from your application, you will need to configure the Application Pool to use mydomainuser as its Identity (found under Advanced Settings...), or you will need to grant share permissions to the computer running IIS if the Application pool uses a built-in account.
The step that was missing is converting Virtual Folder as Application.
Right-click the Virtual Folder myphotos, click on Convert to Application
The link here should explain the steps
Without adding Server.MapPath, it works fine. For example
image.src = "~/myphotos/myimage.jpg"
I'm creating multiple small ASP.Net Web forms applications i want on my host each project of those to run in different subfolders for the root directory of my host. When i puplish each project to different subfolders of the root directory all of them dont work. The only one that works is the one at the root directory. I think this issue is related to Web.Config. I want to ask is there a way to run each application of those in different subfolder without creating other websites ??
IIS
I have been doing this a lot for testing purpose before final deploy. I just host the new application in the virtual directory of the the existing website that we own.
for eg:- www.example.com is our site
and we have a application named xyz then url for new application will be : www.example.com/xyz
You have to add a virtual directory in the root of the IIS website and turn it into an application by right-clicking on it in the IIS management console.
Or simply you can put the website in your root website (as in your case) and then in the IIS management console convert that folder to application.
Create and Configure Virtual Directories
Setting Virtual Directories as Applications in IIS
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?
I would like to nest asp.net web app within sitecore site, something like this:
<sitecore web root folder>
.
<virtual directory/app folder>
I want to access sitecore site by using following url:
http://<whatever site name>
and I would like to access web app by using following url:
http://<whatever site name>/<whatever virtual directory/app alias>
Is this possible?
I tried it but when I try to access my web app (not sitecore) then web app complains about missing sitecore.
I believe that is because now I have two config files ans when accessing web app iis/asp.net processing first sitecore web.config.
Right, your assumption is correct. See Creating a project in a virtual directory under Sitecore root article for more information about this kind of setup.
You should be able to create a virtual app under a Sitecore root path. Because its an app it will use its own app pool and you can have a web.config for it. I guess the physical files will be OUTSIDE of the Sitecore Website folder but the from a URL you can make the virtual app located anywhere below the Sitecore root.
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.