IIS Site inside another site, different web.config - asp.net

I have an MVC web app on my iis with windows authentication. I have a folder called Content which holds all of my images.
I want that the Content folder will be freely excessed so I converted the Content folder to an application. The problem is that my main web.config is being read and it looks for WebGrease in Content/bin which it obviously cant find.
Is there a way to make the Content web app use a different web.config?

I succeeded by wrapping some of my web config sections in my parent's web.config with the location tag
https://msdn.microsoft.com/en-us/library/b6x6shw7(v=vs.100).aspx

Related

Is there a way to tell a View in ASP.NET where to look for a Web.Config?

I've recently began a new project and I've decided to try to arrange the folders in a basic ASP.NET MVC project by feature (i.e. one folder would contain all Account files Models, View and Controller and another folder would contain Home Model, View and Controller etc...) instead of the default ASP.NET template. With this being said I quickly realized when I moved my views my controller was looking under the views folder. I fixed that but then my views were looking for the Web.Config and I fixed that by copying the views folder Web.Config into that folder. This is a solution but I want to know if I can point all my views to one Web.Config without having to have them all in the same folder.
Every folder in ASP.NET web application / website can have its own web.config file. Having said that, it is also necessary that the root folder of your application must have a web.config file based on which the application / website will be configured in the hosting environment.
Therefore, if you want to use different settings for different folders, you can place a separate web.config file with settings specific to folder in the any of the application folder.

How to use host headers in IIS for a web application?

I have configured a website in IIS with a host header, so that I can call the url customhostheader/ and the website will be shown.
When I try to publish my web project, I get the error that some sections in web.config are registered as allowDefinition=MachineToApplication. But I cannot convert the website in to an application in IIS. I can only convert virtual directories into IIS applications, but I don't want the much longer url http://customhostheader/virtualdirectoryname, I prefer to have just http://customhostheader.
Any ideas what I could do?
Thanks.
Add an application with the name customhostheader which is pointing to your published code (parent of bin folder)
To do this
Right click on "Default Web Site" in IIS and select "Add
Application"
Give alias as customhostheader and provide the path to your application.
Edit based on the comment
Each website by default contains an application. So we just needs to make sure the path of the website is correct.
The following two points should be enough to set up the correct path
The path should be parent of bin folder
The web.config should be present on the path
The default document can be set through the IIS or web.config

ASP.NET MVC 3 - Images not found if deploy as application on IIS 7.5

I have an ASP.NET MVC 3 website which is running on http://localhost/. I also have a new project (ASP.NET MVC3) and I want to deploy it as application
so the url will look like http://localhost/child/
But I have problems with images. If I create image using <img src="/content/img/site-logo.png" alt="logo" />
the image is not available, because the actual URL should be /child/content/img/site-logo.png.
I can solve it if I put url in Url.Content("~/content/img/site-logo.png")
but I don't want to change all my images now.
Is it some more easy solution? Some IIS 7 settings?
I had the same issue, but I found the reason why it was forcing authentication on the Contents folder.
When a user is not logged in yet, they are classified as Anonymous Authentication. In IIS7 (which is what I am using, guessing it is the same in IIS6) you need to open the authentication window in features view. Then edit the Anonymous Authentication, to use your application pool identity, or the default one, just make sure that user has permissions to read in that folder.
That fixed it for me, hope it works for you.
I can solve it if I put url in
Url.Content("~/content/img/site-logo.png") but I don't want to change
all my images now.
I am not aware of any IIS setting, other than of course setting your application to run at the root of the IIS web site.
You should always use url helpers when dealing with urls in an ASP.NET MVC application. So you really should change all hardcoded urls, and by the way this doesn't include only images, it could be also anchor hrefs, form actions, hardcoded urls in your javascript files, ...
You can create virtual directory in root iis project and point it on directory with images. BUT, you should better spend this time to clean up your image paths because it, probably, will bite you in future again.

IIS 6.0 web application - Does the entire "website" need to be an "application"?

I had a website hosted in IIS. One small section of it needed asp.net. So I just right-clicked that section/directory and made it an application and a virtual directory.
Is that alright? Or does the entire "website" need to be made into an application and virtual directory?
The reason I ask is that when I try to browse to the aspx page in this "application", I am getting a parser error message "Could not load type...MyCodeBehindType" in the page directive, which seems to me to indicate that it is not finding the dll's, or even the code behind class files (which are clearly in the same directory).
EDIT:
If I do it this way, with only a subfolder of my website actually being a web application, where do I put the dlls? In a bin folder of the website the web application is within? Or in a bin folder of the web application?
Making just a folder within a website, an application, should be fine. I usually have to remember to change the version of ASP.NET from 1.1 to 2.x, that may be what's causing the error.
In order to test the configuration, start with a blank test page (blank.aspx) with just HTML. If the HTML shows up, you know IIS is serving .NET pages.
If there is a problem with ASP.NET not being correctly registered for IIS, you could try re-registering it. Open the following folder:
%WindowsDir%\Microsoft.NET\Framework\x.x.x\
and run:
aspnet_regiis.exe -i

web.config in nested folder

I am trying to install an app inside of another web app. I have my .aspx pages and some code that I was putting into the main app's app_code folder. I've added my own web.config file for my connection string and such but I think there's a conflict. So my question is a two parter. First, what is the best way to install an app inside of another app, i.e should I use the main apps app_code folder or add my own, and second, would there be a conflict with the two web.config files. I was under the impression that the files pulled from the most specific web.config file. It appears there is a problem with my security and I am unable to access my file. I was attributing this to the two web.config files,
thanks.
If the nested application has had its folder turned into an application (right-click on it in IIS, Properties, and on the "Application" tab, "Create" a new application), you should put the code in the local App_Code folder:
- \RootFolder // Root of website
|- \App_Code // App_Code at root
|- \NewApplication // Seperate application in IIS, has "web in a box" icon in IIS
| |- \App_Code // App_Code of new application
If the nested application isn't a true application (in the IIS sense), then you will need to have the code files in the root App_Code folder.
This also has a bearing on your web.config - if the nested application is a true application, then you'll be able to have a full web.config at the level you want - however if it's not an IIS application, then there are limitations as to what you are able to put in subsequent web.configs - some elements are only allowed in the web.config at the application root, and can't be overridden by other settings.
What's the actual error you are seeing?
Regarding your first question, I would rather have them deployed on different folder. And second, if you have, for instance, a web site inside the default web site, you will have both web.config, but the more specific will override some of the attributes of the web.config from the default web site, but the ones that are not override will be there, (ie, HTTPHandlers, HTTPModules, the site will try to load those, so you will need to add the remove tag inside the HttpModules to remove them).
Hope this clarify your question

Resources