Web.config for .net deployment to Azure app service - c#

I have ran into an issue where I am trying to deploy my api to a folder inside of app service on azure.
When I deployed directly to root directory it was working fine but the requirement is to have it in a api folder.
What I have done so far:
on Azure portal inside of the configuratation->PathMappings i have added:
virtual path = /api
physical path = site\wwwroot\api
I downloaded the publishing profile directly from the portal. Imported it and changed the site url and destination url to have /api appended. I have been following this tutorial.
The deployment is executing fine from VS. I verified all files are there via FTP. When I try to navigate to the url I get a 404 error. The root directory shows the hostingstart.htm page.
From what I gathered it is to do with the web.config not being in the root directory and the service basically does not know how to handle this request.
So finally, my question is:
How should the web.config look like for a set up where the root director will serve flat html/css/js files and the api will sit inside of /api folder ?

There is a Virtual applications and directories setting in the web app, which fully meets your needs.But the directory structure is different.
You can see my answer in another post, which has a specific introduction and points of attention.
My answer describes adding a sub application, you can also add access to static resource files.
In solving your problem, the services you need to use are Front Door, and you need to pay attention to the need to modify the .csproj file.

Related

how can I locate site web.config in an IIS virtual folder instead of site root

I have multiple instances of an ASP.NET web application that are identical in every way except for the web.config file, which contains the instance-specific settings. In order to avoid having multiple copies of the same set of files, I want to place all or part of the web.config file in an IIS virtual folder.
I created an IIS virtual folder "config" under the site root folder and used the following line in the web.config file to refer to it:
<appSettings configSource="config\\app.config" />
Unfortunately, IIS looks for a physical path under the site root folder named "config", and coughs up an error when it can't find it.
Does anyone know a way to trick IIS into using the IIS virtual folder? I am also open any suggestions (including server-side code) on how to accomplish the same goal (using the same folder to serve multiple instances of the same web site differing only by appSettings).
I have also considered dumping all the content into a virtual "web" folder, but this would require re-basing all references in nearly 200 files. Using the tag is not a viable solution here because it re-bases everything including same page references, yet inexplicably does not work for references to .less files.
Edit: while the idea is to use the same folder for multiple instances, I want to make it clear that each instance would be set up in IIS as a separate web site/application. It's just that each instance would point to the same physical folder.
After doing more research, I found a workable solution to this. It is true that a direct reference using configSource to another config file in a virtual folder is not possible because folder references in web.config files are expected to be physical references. However, IIS virtual directories can each have their own web.config files. My solution is:
1) Create a virtual folder under your site in IIS. Point it to whatever physical path you want.
2) Add a web.config file to that folder containing the contents specific to that instance of your site. From the example in my original post, that would be the appSettings section.
3) In your server-side code, use the System.Xml.XPath methods to iterate through the web.config file using the path returned by System.Web.HttpContext.Current.Server.MapPath("config/web.config"). MapPath converts the IIS virtual folder relative reference to a usable physical reference on the server.
Using web.config in the virtual folder has another benefit in that it will be invisible to client browsers, just as the site web.config is.
Using the above method, the same binaries and client viewable files can be used from one source physical location to serve multiple IIS instances of the same site differing only by the contents of the web.config file stored in the "config" IIS virtual folder. Obviously, each instance of the application in IIS would point its config virtual folder to a different physical location with its own web.config file.
I have tested this and it works.
No, you cannot. Virtual directory is an IIS concept, but the config file redirection you use (separate config file) is a .NET/ASP.NET concept. Thus, when the separate config file is being discovered, only physical directories are searched, because the searching algorithm has no idea what is virtual directories and how to find them in IIS configuration.
Why can't you try Web config transformation for multiple environments. I have given a sample link to start up
http://deanhume.com/home/blogpost/working-with-multiple-web-config-files/4100

"..allowDefinition='MachineToApplication' beyond application level" error on deploying the website on web host

I came across the solution of this genetic problem all across the internet and Stackoverflow, but none of them talk about the same after/on deployment. I also read this famous article . So, my website runs absolutely fine via VS 2010. However, I get this problem the moment I deploy my website using the copy tool of VS 2010.
There are three web.config files in. 1- root, 2- Users folder, 3- accounts folder. The tag exists in the web.config file in the root. The hierarchy of which looks like: domain.com / httpdocs / websitefolder / web.config. In the websitefolder there are Accounts and Users folders which further contain web.configs, but non of them have the tag.
What could possibly go wrong from the development machine to deployment? The error I am getting is on line:
Line 16: <authentication mode="Forms">
In the httpdocs, there are other projects with web.configs, can that be a problem? In that case, I also deleted their contents, but didn't help (but may be I should have done a better job? I don't know if this is what was required at all?).
Also, this is a website, so there's no bin or obj folder being created, none of that kind of issue. Please suggest, I am not able to figure out the problem. Thanks a lot.
Usually when you have multiple sites in sub directories of one site, inspite you delete a web.config, the problem will persist. In that case even the sub folders should be marked as an application.
Is the folder in which you have this website deployed an application in IIS? It is one main reason why this error could occur.
If its not, make it as an application and the problem should resolve.
Update: Seems you have used File System while developing your website.
Firstly install IIS server like "this".
Next you should create a virtual directory in IIS. See "this" . (in physical path, select the path upto your deployment folder)
Now run the website. If your problem is solved it means the issue is with the virtual directory in your remote server. So report them.

Img tag not showing image in windows azure cloud service

I deployed my MVC-3 project on the windowsAzure cloud service. Then when i opened it through
staging url. The images are not showns in my application. My image src is a relative address which is :
<img src="/images/1.jpg" alt="Lion" />
I am using jquery-UI as well but it plugins like ( button ) are also not working. I used cycle plugin, pagination plugin these are aslo not working. Whats the problem ?
altho your path 'appears' relative, you'll need to use the Url helper to navigate the folder structure correctly. Try using the below instead:
<img src='#Url.Content("~/images/1.jpg")' alt="Lion" />
All remote hosting is fickle and Azure is certainly no exception. This issue always catches me out if I omit the #Url.Content() helper. I'm certain this will work.
The problem probably is because your image is not imported in the MVC project. When you deploy a Cloud Service, only the resources that are in the project are deployed. Resources that are just in your file system are not.
I had this same issue and did the following:
my Images folder was outside the \Content directory, therefore, I created a directory inside this directory, so now I had \Content\images
I now moved my images to this new directory
Did a right-click on the images folder name in the Solution Explorer and clicked on option "Include in Project", I also did a right-click on the images itself and chose same option
Published and Voila it worked!
I had the same issue. I remote desktop to my server in Azure, opened IIS, went to the folder where I have the images and tried to Browse it, I got an Internal Server Error telling me "The requested page cannot be accessed because the related configuration data for the page is invalid". The issue was with this staticContent definition:
<mimeMap fileExtension=".mp4" mimeType="video/mp4"/>
So I opened the web.config, searched for "mp4" and removed the section where I was defining that mimeMap.
After that I could browse the image and when I refreshed my page in my local machine all images showed up.
I then deleted that mimeMap definition from my Web.Release.config file. I had created it because previously I had published this project as a WebSite in azure and I couldn't deliver mp4 videos using the tag, but that seems not to be necessary when using a Cloud Service.
Hope this helps.

Access to the path 'C:\xxx\yyy\zzz\abcd_20120309.pdf' is denied

I have an ASP.Net website and a C# console application (both developed in VS2010). Both upload files to our web server (Windows Server 2003/IIS 6.0). Users logging in to the website can then view and download these files.
This works fine in website. But when I try to download files uploaded by the console application, I get the error:
UnauthorizedAccessException
Access to the path 'C:\xxx\yyy\zzz\abcd_20120309.pdf' is denied.
I have already manually provided "Full Control" to NETWORK SERVICE account for that folder.
Why is Asp.Net code unable to access a folder created by the console application?
Any idea?
Thanks!
You need to provide access to the folder for IIS_IUSRS (or something along this line).
AKA you need access for IIS.
Including access to everyone, doesnt include this user. So it must be done directly.
Network service will not suffice.
If IIS_IUSRS doesnt appear in the list, search for it.
Don't know if it matters in this case but one thing I have seen in the past is:
The application first saves the file in a temporary folder and then moves it to the target folder.
Sometimes, don't know the exact rules, the file access right follows the file in the move. i.e. the file ends up with the access rights for the temporary folder even in target folder.
Check the access rights on the file and see if it differs from the target folder.

Deleting Directory at runtime

I just want to delete the Directory which is in the project folder.
That folder having all web sharing authority and permission.
The problem is arising when i am deleting the folder.
Folder is deleted from the serverpath(Virtual Directory).
But my problem is that when i complete my task and click on any control it will redirect me to the Login page with the return url as there is a secure authentication on the root directory is available
Application domain recycled when
Sub-Directories are deleted, that's why your session will lost and you are redirected to the login page.
For more details, check this article from MSDN Blog and read Why does an application domain recycle? from here
ASP.NET Case Study: Lost session variables and appdomain recycles
and also check this one Deleting ASP.NET 2.0 Application Sub-Directories Shuts Down the AppDomain
As noted in another answer, this is because the web app is restarted whenever you delete a folder inside the web app's directory structure (i.e. below the web app's root directory).
The only solution I found for this problem is to move the data directories (which you create/delete/modify) outside the web app's root directory / virtual directory.
Then we create a link (junction) in the file system so that the directory appears to be inside the virtual directory. This prevents ASP.NET from monitoring the data directory for delete operations.
Example:
Our web site (virtual directory) is located at C:\projectX\website
the data directory (where we create/delete files and folders) is located at C:\projectX\data
then we create a link which makes the data folder available as C:\projectX\website\data
The link is created using the program Linkd.exe (available in the windows resource kit), with the following command:
linkd c:\projectX\website\data c:\projectX\data
Now C:\projectX\website\data is a link/junction which points to the real data directory. Inside your web app, you can continue working as if the data directory were a physical directory below the web app's root directory.
E.g. in your web site you can access the data folder using this code:
Server.MapPath("~/data")
And you can also used the windows file explorer and browse to C:\projectX\website\data. It appears just like a real directory.
As you can see, you can continue to use the linked data folder as if it were a normal folder inside the web app's directory. The only difference is that ASP.NET will not track the directory for delete operations and will therefore not restart the application. This means, you can now create/delete/modify folders and files inside the ~/data directory as you wish, without having the web app restarted.
Can you replace folder from the project root into the App_Data folder?

Categories