How to deploy a website to a local IIS - asp.net-mvc

I'm trying to deploy a website to my local IIS for the first time
I added a new website to my local IIS (also created a directory for it)
I published it with File System method from VS2012 to this directory (checked - it's in there)
I clicked Manage WebSite > Browse
This shows an error:
HTTP Error 403.14 - Forbidden The Web server is configured to not list
the contents of this directory.
I found on the web that I should enable Directory Browsing. I tried it.
Now it shows me my app root directory instead of loading the web app (that's not what I wanted...)
How to make IIS launch my web app?

You need to grant permission to that folder.
When i deploy on IIS i grant "network service" read write access to the folder

You will need to launch the IIS Management Console and within the Default Website, your website folder should hopefully be listed. Do a right click on the website folder and click "Convert to Application"
You may want to consider using Web Deploy as it will simplify the deployment process.

If it's an MVC app, then the default controller & action in the routing need to correspond with a controller & action in your app. By default this would be the Index action in HomeController. If your default is some other combination, change the defaults in the routing config.
If you have a home/index controller/action, then check your server is configured to run aspx pages. do this by simply creating a default.aspx with some text in it & see if it's served when you browse the folder.
Directory Browsing should be disabled, as it would allow someone to browse the files on your server. I know it's your localhost, but good practice & all that.

I finally found it. It wasn's an IIS problem. One of my colleagues added the following lines to the Web.config
<system.webServer>
<handlers>
<remove name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" />
<remove name="ExtensionlessUrlHandler-Integrated-4.0" />
...
</handlers>
...
</system.webServer>
Removing them fixed the problem.

Related

Host MVC application in an existing site

I am already running a site where there are webforms and classic asp running concurrently. Now I have created a new project with MVC and trying to upload it to the site. I have published it in my local and uploaded files to site. But when I am trying to ping the url if says 404(file not found).
In order to get exact problem please add the following to your web.config under
<system.web>
<customErrors mode="Off" />
...
Then come back with your problem.

Publishing an MVC4 App on IIS 7.5 but Having Permission Issues

I published an intranet on IIS 7.5. If I try to go to the website, I get "403 - Forbidden: Access is denied - You do not have permission to view this directory or page using the credentials that you supplied".
If I right click on the application folder on IIS Manager and go to Manage Application and then Browse, I get "HTTP Error 403.14 - Forbidden - The Web server is configured to not list the contents of this directory". It then proceeds to tell me that A default document is not configured etc. etc. I do have a default document listed in the web.config file as follows:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<directoryBrowse enabled="false" />
<modules runAllManagedModulesForAllRequests="true" />
<defaultDocument>
<files>
<add value="Index.cshtml" />
</files>
</defaultDocument>
</system.webServer>
</configuration>
What am I doing wrong? Many thanks.
check the folders permissions: right click on the folder, click on properties go to Security and add the appropriate user (like IUSR_...). hope it helps.
It turned out I was publishing the app completely the wrong way. I was going by how previous ASP.Net apps created as Websites and not Solutions were published. This MVC app needed to be placed in inetpub/wwwroot folder in the server. If I published through Visual Studio I think this would have happened anyway. I didn't have VS in the server. So I placed the files manually there (just copied from my local inetpub/wwwroot since I successfully published there earlier). The last thing I needed to do was go to IIS Manager and converting the project folder into an Application. Now cooking on gas.

MVC website running on localhost

I've built a little time recording website with MVC4, which I'd like to use to record my time.
Previously, coming from a WebForms background, I'd build an app like this and set it up in IIS as an Application off Default Web Site pointing to the folder, so the URL would be http://localhost/Timesheet
I tried that with the MVC project, but I get a 500 Internal Server error. I assume this is because it's a project vs. a website. If the project is "running" in Visual Studio, then it works, but I don't want to have to open Visual Studio every time I want to record some task I worked on.
I tried adding it as a separate site under the "Sites" folder in IIS, but then I'm not sure what the Host name should be - it won't allow localhost/Timesheet for example.
Is this even possible?
Turns out I just needed to wrap the root web.config's system.web section in:
<location path="." inheritInChildApplications="false">
<system.web>
...
</system.web>
</location>

HTTP Error 403.14 - Forbidden The Web server is configured to not list the contents

I have downloaded the MVC Music Store ASP.NET application at location C:\Users\DEVESH\Desktop\Projects\MvcMusicStore-v3.0\MvcMusicStore-Completed\MvcMusicStore
and added the website on IIS at the same location. I have also given permission to IIS_IUSRS, but when I run localhost I am getting the error:
HTTP Error 403.14 - Forbidden The Web server is configured to not list the contents of this directory.
I have googled it, but have not found a fix. What I am doing wrong?
I came across this error because I had the wrong .NET version (v2.0 instead of v4.0) configured on the web site application pool. I fixed it this way on Windows Server 2008 R2 and IIS 7. I'm pretty sure the instructions apply to Windows Server 2012 and IIS 8 as well:
Press keys Windows+R to open the Run dialog, type inetmgr and then click OK. This opens the IIS Manager.
In the left treeview, locate the Sites node and find the Default Web Site node under it (or the name of the site where the error message appears).
Right-click the node and select Manage web site -> Advanced settings.... Note the name of the value Application pool. Close this dialog.
In the treeview to the left, locate and select the node Application pools.
In the list to the right, locate the Application pool with the same name as the one you noted in the web site settings. Right-click it and select Advanced settings...
Make sure that the .NET Framework version value is v4.0. Click OK.
This doesn't apply if you're running an older site that actually should have .NET v2.0, of course :)
In my case ASP.NET not registered on server. try to execute this in command prompt:
Windows 32bit
%windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_regiis.exe -ir
Windows 64bit
%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_regiis.exe -ir
Just in case if anyone reached here looking for solution, here is how i resolved it. By mistake I deleted all files from my server ( bin directory ) but when i recopied all files i missed App_global.asax.dll and App_global.asax.compiled files. Because these files were missing IIS was giving me this error
403 - Forbidden: Access is denied.
As soon as i added these files, it started working perfectly fine.
I resolved this issue by correcting an error with my Global.asax file arrangement. I had copied across the files from another project and failed to embed the Global.asax.cs within the Global.asax file (both files previously existed at the same level).
In my case when I browsed to
site5.com
I got the following error.
HTTP Error 403.14 - Forbidden
The Web server is configured to not list the contents of this directory.
Most likely causes:
A default document is not configured for the requested URL, and directory browsing is not enabled on the server.
And then when I browsed to
site5.com/home/index
I was met with
HTTP Error 404.0 - Not Found
The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.
Most likely causes:
The directory or file specified does not exist on the Web server.
The URL contains a typographical error.
A custom filter or module, such as URLScan, restricts access to the file.
All that I did is installed the feature in IIS ASP.NET 4.8 as shown below.
I was using ASP.NET 4.5 MVC application on IIS 7. My fix was to set runallmanagedmodule to true.
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" />
</system.webServer>
or If you have other modules, you may want to add them inside the module tag.
<system.webServer>
<modules runAllManagedModulesForAllRequests="true">
<add name="ErrorLogWeb" type="Elmah.ErrorLogModule, Elmah" preCondition="managedHandler" />
...
</modules>
</system.webServer>
IIS Modules Overview : The Official Microsoft IIS Site
I have encountered similar myself before for 2 reasons;
1. MVC is not installed.
2. The url routing module is not registered (this varies by machine in my workplace for a reason I cannot fully explain - it is not always registered at a system level ), try registering it in the application web.config:
<system.web>
...
<httpModules>
...
<add name="UrlRoutingModule" type="System.Web.Routing.UrlRoutingModule, System.Web.Routing, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
</httpModules>
</system.web>
Edit: I forgot to add the location for iis 7+:
<system.webServer>
<modules>
...
<add name="UrlRoutingModule" type="System.Web.Routing.UrlRoutingModule, System.Web.Routing, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
</modules>
</system.webServer>
This error can happen when, in IIS Manager, the ASP.NET MVC site is pointed to the wrong directory.
In my case, I inadvertently had the site pointed to the solution directory instead of the child project directory. That is, I had the site's Physical path set to
C:\dev\MySolution
instead of
C:\dev\MySolution\MyProject.
Specific steps to fix this:
Open IIS Manager (Start > Run > inetmgr);
In IIS Manager, in the left pane, expand Sites;
Under Sites, left-click the ASP.NET MVC website;
In the right pane, click Basic Settings...;
In the Edit Site dialog, change the Physical path to the project directory.
Click OK.
This error occurs when the application cannot startup.
So the cause can be anything that prevents your application to start.
Wrong connection string
Wrong IIS directory permissions
An exception thrown in your Application_Start() function
IOC Container initialization error
IIS ASP.NET registration errors
Missing DLL in your bin folder
etc...
I faced a similar (but not identical) issue.
I had to go to to Turn Windows features on or off in Control Panel and add ASP.NET 3.5 and 4.7:
Then it worked for me.
I've just had the same problem, but my fix was that the Routing was not configured in the Global.asax.cs file. I'm using Bootstrapper and Castle Windsor, so to resolve this problem I added the following code to Global.asax.cs:
public class MvcApplication : System.Web.HttpApplication
{
protected void Application_Start()
{
Bootstrapper.IncludingOnly.Assembly(Assembly.GetAssembly(typeof(WindsorRegistration)))
.With
.Windsor()
.With
.StartupTasks()
.Start();
}
}
Obviously if you are using the basic MVC then you will need to reference the RouteConfig file in the AppStart folder instead:
public class MvcApplication : System.Web.HttpApplication
{
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
BundleConfig.RegisterBundles(BundleTable.Bundles);
}
}
In my case, i had multiple projects but i had not defined the starting Project.
So this error was generating.
After defining the startUp project solved the issue.
I had this error after creating an empty ASP.Net application in Visual Studio. As soon as I added a file index.html to the main solution, it worked. So in my case, I just needed to add a file to the root of the project folder.
Check this also:
This problem occurs because the Web site does not have the Directory Browsing feature enabled, and the default document is not configured. To resolve this problem, use one of the following methods:
Method 1: Enable the Directory Browsing feature in IIS (Recommended)
Method 2: Add a default document Method
Method 3: Enable the Directory Browsing feature in IIS Express
LINK : https://support.microsoft.com/en-us/kb/942062
If project is a ASP.net MVC project it would be about routing.
In my case I changed default routing values:
routes.MapRoute(
"Default",
"{controller}/{action}/{id}",
new { controller = "Home", action = "Index", id = "" }
);
I changed my code accidentally to:
routes.MapRoute(
"Default",
"{controller}/{action}/{JobID}",
new { controller = "Home", action = "Index", id = "" }
);
Thats I only changed "id" to "JobId" and default route can not be find.
In my case index.aspx file was not created by default and after adding another web form i did not set the form as start page ...After setting the page as start page my issue get resolved .
So right click a web form and set the form as start page
:)
IUSR permissions use on a folder if not under inetpub/wwwroot will be solution for some.
In my case, I had to disable 'Exclude files from the App_Data folder' in my publish profile to deploy the App_Data folder with my XML documentation (XmlDocument.xml). That got rid of the 403.14.
in my case:
1. in IIS Manager, in left tree, left click the computer name, in right dialog click ISAPI and CGT limitation, in open dialog, select ASP.NET v4.0.30319 and select enable. There is two ASP.Net v4.0, one for 32bit, another for 64 bit. select depending on your OS bit.
2. in left tree select app pool, in right dialog, select the app pool your website used. double click that pool, in open dialog, .net framke item select .net framework v.4.0.30319. and pipe..item select integate.
Maybe there is some wrong translation above because my OS is not English version.
In case anyone comes across this for a project other than MVC:
My project was a WCF project, which runs off .svc files--no default document. As a result I got a 403.14 error at myhost.com/ but as soon as I added a baseAddress path from my web.config file (ex. myhost.com/mybaseaddresspath.svc I got a webpage.
My colleagues made a URL Rewrite rule, which reduced all URLs to a StaticFileHandler; mapped to a file path at the root of my Application physical folder.
(i.e. an over-aggressive URL rewrite means that my Controllers/Actions were not working)
Check your applications' URL Rewrite rules to confirm they do what you expect.
I faced the same issue while developing Business Central application.
Open Business Central Application and Edit Web Client Base URL
under Client Services.
You can enter http://localhost:8080/YourWebServerInstance/
I faced similar issue. My controller name was documents. It manages uploaded documents. It was working fine and started showing this error after completion of code. The mistake I did is - Created a folder 'Documents' to save the uploaded files. So controller name and folder name were same - which made the issue.

Getting 404 error on MVC web-site

I have an IIS7.5 web-site, on Windows Server 2008, with an ASP.NET MVC2 web-site deployed to it. The website was built in Visual Studio 2008, targeting .NET 3.5, and IIS 5.1 has been successfully configured to run it as well, for local testing.
However, whenever I try and navigate to a page running in IIS7, I get a 404 error.
I have checked the following things:
There is no corresponding 404 log entry in IIS logs.
Actually, there are 404 entries in the IIS log.
The application pool for the web-site is set to use the Integrated pipeline.
The "customErrors" mode is set to off.
.NET 3.5 SP1 is installed
ASP.NET MVC 2 is installed
I've used MVC Diagnostics to confirm all MVC DLLs are being found.
ASP.NET is enabled in IIS, which we've demonstrated by running the MVC Diagnostics page.
KB 2023146 did highlight that HTTP Redirection was off, so we've turned it on, but no joy.
EDIT
Ok, so we've installed the world's simplest MVC application (the one which is created when you create a new MVC2 project in Visual Studio), and we are still getting 404s on any page we try and access - e.g.
<my_server>/Home/About will generate a 404.
Any ideas will be greatly appreciated!
This is quite often caused by the following missing from the web.config:
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
Do you have a problem with just 1 page or the whole site is not working?
A) 1 page
You can use RouteDebugger to verify if the route is matched correctly
B) Whole site
I assume you're using Windows Server - check if ASP.NET is enabled in IIS - it's disabled by default, I believe.
You can use MvcDiagnostics page to check if all dlls are deployed properly.
Are you running in IIS7 integrated mode? Classic mode of IIS7 does not automatically map extensionless URLs to ASP.NET (much like IIS6)
Make sure your Web.config tag is configured correctly.
We finally nailed this issue by exporting the IIS configuration of a working server, and comparing it to ours.
It was a really obscure setting which had been changed from the default.
IIS ROOT → request Filtering → Filename Extensions Tab → Edit Feature Settings → Allow unlisted file name extensions
This should be ticked.
This can be set at the IIS level, or the site-level.
Glad that fixed your problem. Others researching this issue should take note of the extensionless URL hotfix: http://support.microsoft.com/kb/980368
If none of the other solutions here solved your issue, check that you have the
Global.asax
file in your website. This solved the issue for me.
Checkout if KB 2023146 applies to your scenario. Also try requesting directly a controller action: /yoursitename/home/index
Apparently this can have many different causes.
For us, the problem was that the DNS entry was configured for two IP addresses, but the IIS configuration would only listen to one of them. So we got unpredictable results, sometimes it would work, sometimes a few files (css, etc) would not load, and sometimes the whole page would not load.
For me it was all about installing .NET Framework 4.6.1 on the server (my app was targeting that version)
You'll also get this if your bindings aren't correct. If you don't have www or a subdomain it'll return a 404.
I had this problem when running my MVC4 site with an app pool set to ASP.NET 4.0 and the Classic pipeline, even though the extension handlers were set in my web.config and were showing correctly in IIS. The site worked in Integrated Pipeline so I knew it was a configuration issue, but I couldn't nail it down. I finally found that ASP.NET 4 was disabled for the server in the ISAPI and CGI Restrictions settings. I enabled ASP.NET 4.0 and it worked.
In addition to checking if you're running in integrated pipeline mode, make sure your application pool is set to use .NET! I recently ran into this problem, and when I went in to check the app pool settings, I found that somehow it had been set to "No Managed Code." Whoops!
My Hosting company fixed this for me by doing this (I removed the original password value of course).
<system.webServer>
<security>
<authentication>
<anonymousAuthentication password="<password>" />
</authentication>
</security>
</system.webServer>
Typically I encounter this issue when there is a Routing problem. I compare a working vs non-working to resolve it.
Today however I accidentially created a Virtual Directory in IIS.
It has to be an Application, right click on the Virtual Directory (with a folder icon) -> Convert to Application:
Don't use runAllManagedModulesForAllRequests. You want to let IIS handle resources such as images.
<system.webServer> <!-- Rather do NOT use this -->
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
Instead add the MVC routing module
<system.webServer>
<modules>
<remove name="UrlRoutingModule-4.0" />
<add name="UrlRoutingModule-4.0" type="System.Web.Routing.UrlRoutingModule" preCondition="" />
</modules>
</system.webServer>

Resources