Some specs:
IIS 7.5
ASP.Net MVC3
I have three MVC3 applications I would like to host:
Project A
Project B
Project C
I want to get the URLs to be like this, respectively:
http://domain/
http://domain/ProjectB
http://domain/ProjectC
So in IIS, I have the default website, which points to the folder for ProjectA. I then added two Applications to it, one pointing to ProjectB, and one to ProjectC, and their respective folders on the hard drive. I am storing the sites in C:\sites. Each project has a folder in C:\sites where the application's files reside. As you can see, the sites are not nested at all on the server.
When I load http://domain/ProjectB, it is trying to load configuration values from the ProjectA web.config. Obviously this is not what I want, and I'm not that awesome at server configuration. I got it working by wrapping most of the ProjectA web.config in a location tag like so:
<location path="." inheritInChildApplications="false" >
<!-- Lots of web.config stuff for ProjectA -->
</location>
I'm not really a fan of this, it feels wrong. To me, it seems like a nested Application in my site in IIS should not even know about the parent site. What am I doing wrong? I'm sure it is something really small. I would have made ProjectA an Application, but I don't want the alias on it, as I want http://domain/ to pull it up for the users.
Again, I am not that knowledgeable about server stuff, it just isn't fun to me, hence why I'm asking y'all!
Thanks!
That is how it works. By default, asp.net applications inherit their parents web.config, and you either need to override those values in your lower web.config or wrap it in an inheritInChildApplications="false" attribute like you did above.
One possible option is if you can make your home page at the root of the site NOT an asp.net application. If you can't, you're stuck doing this.
on goDaddy you can create iis virtual directories with "set application root", which then makes each director with "set application root" set act as a root directory (just as you want). The user don't notice anything. So you could look and see if you have that option?
Related
after updating my test project to beta8 (not without a huge pain), I finally managed to have my project up and running.
Now, every time I try to debug with IISExpress, I have explicitly point to the page "index.html" and this breaks my angularjs app.
There is a way to map index.html as default document in IIS Express?
I think you need to properly configure the middleware:
app.UseDefaultFiles();
It has some overrides if you need them. You can find more details here.
I have created a small site, on IIS express all is working fine. I have created on IIS new application and deployed the package to the folder. the server side is asp.net webapi. the bundle configuration is loading fine when i try to enter the home page, how ever the java script files which are referenced on the cshtml page cannot be found
<script src="~/Client/lib/require/require.js" data-main="../../Client/app/requireConfig"></script>
i am getting -
require.js
/Client/lib/require --> 404 cannot be found
and the bundle which works
viewingPanelDirective.js
/NGWeb/Client/app/appComponents/viewingPanel
how can I over come it?
I think i know what might be the cause, i had the same problem myself
in you visualstudio, the js file was running on a url like this
http://localhost:/client/lib/require/require.js
now you published it, and added it as an application to your default site, you would have given it an alias (e.g) "testsite"
meaning that in reality the file is hosted at
http://localhost/testsite/client/lib/require.js
but in reality your site is looking for it (because of the ~) at
http://localhost/client/lib etc etc
Edit in response to comment:
rather than removing the ~ (which you will need to navigate you back to the url root), i would rather just include your app name in the bundles virtual path, like this:
bundles.Add(new styleBundle("~/yourAppName/Content/css")) ....... etc
I also came across this post, I haven't tried it myself but it seems an interesting alternative to my method.
Fixing Relative CSS Paths when using .NET MVC 4 Bundling
I would like to try testing virtual hosting of an ASP.Net MVC website on my local machine. In Visual Studio in the Web tab of the properties file for the MVC project, I selected Use Local IIS Web Server. By "virtual hosting", what I really mean is that I'm trying to make sure that pages load correctly for urls of the form http://sub-domain-i.my-domain.com/MyMvcProject/Controller/Action, where I'm hoping to test multiple subdomains in place of sub-domain-i. In production, everything will be running under a single IP address on one server. I also hope to test https for urls of this form using a wildcard ssl certificate, but currently I'm having trouble configuring Visual Studio to just test regular http. Prior to worrying about sub-domains, the Project Url field in the Web tab of the properties folder for my MVC project said "http://localhost/MyMvcProject", and everything worked fine. However, after changing this to "http://sub-domain-1.my-domain.com/MyMvcProject" and then adding the following line into my C:\Windows\System32\drivers\etc\hosts file,
127.0.0.1 sub-domain-1.my-domain.com
Visual Studio produces the error "Unable to create the virtual directory. http://sub-domain-1.my-domain.com/MyMvcProject". Does anyone know what I might be doing wrong?
Many thanks in advance!
Edit: I've just discovered that if I select Use Custom Web Server instead of Use Local IIS Web server, it works and I don't get the popup error from Visual Studio. I'm still not sure why this solution works, though, or what I was doing wrong by selecting Use Custom Web Server...
A little late, but I hope it helps somebody.
You need to create the binding in the IIS website prior to add it to the project url of the project. That binding must be like
http | sub-domain-1.my-domain.com | 80 | * or 127.0.0.1
How to create a binding
I have two applications setup in IIS7.5. MVC 3 is installed. One application serves Razor files fine. A separate application was recently created that will not serve Razor files. I get the following error when accessing the file using the full filename (file.cshtml):
This type of page is not served.
Description: The type of page you have requested is not served because it has been explicitly forbidden. The extension '.cshtml' may be incorrect. Please review the URL below and make sure that it is spelled correctly.
When trying to access the file without an extension (/path/file/) I get a 404 error.
I have searched for this problem but haven't found a solution where it works with one application but not another on the same server.
Both applications are using the same App Pool.
Web.Config files are identical.
Do both sites have a CSHTML file in the root of the application? Since the WebPages framework (which is what is used when you request a CSHTML file directly) has a significant impact on your site's performance if you aren't using it, we only start it if there's a CSHTML file in the root folder of your site (i.e. ~/Foo.cshtml). If you don't have any CSHTML files in your root, you can also add a web.config entry to set an appSetting:
<configuration>
<appSettings>
<add key="webpages:Enabled" value="true" />
</appSettings>
</configuration>
If you're confused by my answer, it would help if you edited your question to add information about the file layout of the two apps. Then I can add some concrete examples to try and clarify things :).
Hope that helps!
I want to prevent users access for my "~/Content/..." folder I wrote it as follow in "Global.asax.cs" and put this line of code at the top of every other routes
routes.IgnoreRoute("Content/{*pathInfo}");
but it does not work. in fact user can see every files in content folder by type the URL in browser.
am I missing something?
How did you figure out that it does not work? Give example.
You may have put it last in the Routing table. So try to move it up so that it gets added to the routing table first. The route collection is an ordered list of routes.
Also try this : Routes.IgnoreRoute("Content/");, but your version of ignore is also correct and it should work.
Lastly, I do not know what you mean when you say the user can see all the contents of the Content folder : Isn't that the point? User must be able to download files from the folder, and we usually just need MVC to ignore the requests from coming into the framework, and so that IIS can directly serve those files.
or did you mean Directory browsing is enabled, and you want to disable that : In that case go to IIS manager, and select your website and look for the Directory browsing option and disable it as shown here.
Your problem cannot be solved by routing constraints. There are 3 significant steps in processing request:
IIS got request.
IIS watch at filesystem and search for direct correspondence to file
If IIS didn't found any file - it gives request to ASP.NET MVC for processing.
So, you need to configure folder security to forbidden direct access to files, but allow access to application, as here.
But I don't recommend to secure folder, that should be shared. I don't believe that your site shouldn't have images to display :) If you have some secured content, you need to create another folder.