MVC4 Intranet site IIS 7, cannot display the webpage - asp.net-mvc-4

I have been at this for hours and still have not figure out what I am doing wrong. I created an MVC4 intranet site and now I am ready to deploy it to IIS on our web server. I setup a site called Portal and from Visual Studio I have performed the 1 click publish using the file system method. The files copied successfully to my site. In IIS I changed authentication to Windows and disabled Anonymous authentication. I even went into my application pool and changed the Load User Profile = true (not sure if I needed to do that). I then hit browse Portal on *:88 and I receive Internet Explorer cannot display the webpage. I checked my Modules and I see UrlRoutingModule-4.0 is managed and inherited. I must be overlooking an obvious setting as this is my first web site. Any help is appreciated. Thank you.
physical path = c:\inetpub\wwwroot\Portal
Site name and Application Pool = Portal (.Net 4 and Pipeline mode: integrated)
type = http
Host name = Portal
Port = 88 (80 was already used and did not work)
IP Address = *
UPDATE: Webconfig (i have custom roles) and Routconfig
<system.web>
<roleManager enabled="true" defaultProvider="DbRoleProvider">
<providers>
<clear />
<add name="DbRoleProvider"
applicationName="Portal"
type="Portal.WebUI.Infrastructure.DbRoleProvider"
connectionStringName="PortalEntities" />
</providers>
</roleManager>
<compilation debug="true" targetFramework="4.0" />
<authentication mode="Windows" />
<authorization>
<deny users="?" />
</authorization>
<pages>
<namespaces>
<add namespace="System.Web.Helpers" />
<add namespace="System.Web.Mvc" />
<add namespace="System.Web.Mvc.Ajax" />
<add namespace="System.Web.Mvc.Html" />
<add namespace="System.Web.Optimization" />
<add namespace="System.Web.Routing" />
<add namespace="System.Web.WebPages" />
</namespaces>
</pages>
</system.web>
<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
<modules runAllManagedModulesForAllRequests="true" />
<handlers>
<remove name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" />
<remove name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" />
<remove name="ExtensionlessUrlHandler-Integrated-4.0" />
<add name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness32" responseBufferLimit="0" />
<add name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness64" responseBufferLimit="0" />
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
</handlers></system.webServer>
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "RequestInfo", action = "Index", id = UrlParameter.Optional }
);
}

so after more experimentation and research I found my problem, and it was a result of never doing this before.
My first problem was I included a host name when I was setting up my application. So when I tried to browse to www.portal.com:85 on the server it did not understand that address and could not connect to anything. However, when I removed the host name and typed in http://localhost:85 it worked. I will have to get with my infrastructure team to set that up.
My second problem was security to our SQL Server. I did not know I had to setup a login for the application pool name. I used the second answer from this post Login failed for user 'IIS APPPOOL\ASP.NET v4.0' because I did not want to change the identity to LocalSystem. Once I setup a login under the SQL Server security the site was functioning. Is that the correct way of doing it?

It would be helpful if you disabled friendly error messages in IE. In "Internet Options" on the Advanced tab, under Browsing deselect "Show friendly HTTP error messages". Then try again. Hopefully then you'll see what the actual issue is as an HTTP status code. Can it not find the server, are you getting a 404 (page not found), a 401 unauthorized, a 500, etc.
With that information it will be much easier to diagnose.

Related

ASP.NET Core custom error pages with restricted access in IIS

I want to restrict access to my ASP.NET Core application by only configuring it in IIS (10).
This is not the problem, as I enable only "Windows authentication" and then I can do
<location path="." inheritInChildApplications="false">
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
</handlers>
<aspNetCore processPath="dotnet" arguments=".\MyDLL.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="inprocess" >
</aspNetCore>
<security>
<authorization>
<remove users="*" roles="" verbs="" />
<add accessType="Allow" users="user.withaccess />
</authorization>
</security>
</system.webServer>
</location>
This works fine, but every user without access just gets a 401 response and no error page.
Normally you could configure something like that:
<location path="." inheritInChildApplications="false">
<system.webServer>
<!-- ... -->
<httpErrors errorMode="Custom" existingResponse="PassThrough">
<remove statusCode="401" subStatusCode="-1" />
<error statusCode="401" subStatusCode="2" prefixLanguageFilePath="" path="401.htm" responseMode="File" />
</httpErrors>
</system.webServer>
</location>
but the custom error page is only accessible by users who already can access the application (trying to open the error page results in a 401 too for unauthorized users).
Now in my case it's currently not possible to change the ASP.NET Core application itself, so I have to do it in IIS.
What do I have to configure that the custom error page can be served, but everything else is protected?

Hosted web api is accessible through browser but not through application

I have hosted web api in iis 10.0 then accessing it's method through browser.
But the same method is not able to access through my MVC application.
Getting 404 Not found issue.
But when i run web api application i am able to access methods through application.
I did some googled and found some handlers that needs to be set in hosted web api web.config. But it also did not worked for me.
Below is my complete system.webserver tag used in web api web.config.
<system.webServer>
<modules runAllManagedModulesForAllRequests="true">
<remove name="WebDAVModule" />
<remove name="FormsAuthentication" />
</modules>
<handlers>
<remove name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" />
<remove name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" />
<remove name="ExtensionlessUrlHandler-Integrated-4.0" />
<remove name="UrlRoutingModule-4.0" />
<remove name="ApiURIs-ISAPI-Integrated-4.0" />
<add name="UrlRoutingModule-4.0" path="*." type="System.Web.Routing.UrlRoutingModule" preCondition="" verb="GET,HEAD,POST,DEBUG,PUT,DELETE" />
<add name="ApiURIs-ISAPI-Integrated-4.0" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" type="System.Web.Handlers.TransferRequestHandler" resourceType="Unspecified" requireAccess="Script" preCondition="integratedMode,runtimeVersionv4.0" />
<!--<add name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS,XYZ" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness32" responseBufferLimit="0" />
<add name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS,XYZ" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness64" responseBufferLimit="0" />
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS,XYZ" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />-->
</handlers>
</system.webServer>
Need help.
I was doing some mistakes when passing the Web api url in application.
e.g: for web api Root url i was using like below:
http://localhost:25968
But it should be like : http://localhost:25968/
Last slash was missing due to it web api method was not accessing through application.

How do I configure this route in asp.net mvc 4?

I currently have a website that is serving static files from a simple website that just points to a directory and I want to replace it by grabbing the files from DropBox.
I already have the files on DropBox and grabbing them is easy BUT I now need a website that will parse the URL to the files and give me the parameters I need to access the files on DropBox.
Typical file URL:
http://companyfiles.mywebsite.com/18/RepZio/companyfiles/subfolder1/SampleFile.docx
The route I configured that I hoped would work:
routes.MapRoute(
name: "Default",
url: "{id}/{dropboxfolder}/companyfiles/{path}",
defaults: new { controller = "CompanyFiles", action = "Index" }
);
I know my issue is all of the extra /'s in my URL, how can I parse whatever comes after /companyfiles/ to be a single parameter?
I cannot change the URL's that are being called since they already exist everywhere else in my system.
1. The file path info can be caught by a wild card matching pattern, like
url: "{id}/{dropboxfolder}/companyfiles/{*path}",
2. In ASP.net Classic mode URL with extension are served by Static file handler. To make all url go through ASP.net pipeline in Integrated mode, the following should be added in system.webserver.handlers section
<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
<modules runAllManagedModulesForAllRequests="true" />
<handlers>
<remove name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" />
<remove name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" />
<remove name="ExtensionlessUrlHandler-Integrated-4.0" />
<add name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness32" responseBufferLimit="0" />
<add name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness64" responseBufferLimit="0" />
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
</handlers>
This should put the urls with extension through asp.net pipeline.
Regards

How do I map all routes in my MVC application to a static file?

I'm currently writing a single page application and would like to map all incoming requests (except /api/{controller}) to my web application to a static file (index.html) in root. The routes to /api need to be accessible for WebApi calls from the front end. Any suggestions on how to achieve this?
You could use the IIS 7 url rewrite module. This module is part of the IIS Express webserver, so you don't need anything special to enable it. And on your production IIS 7 server you might need to install and enable the extension.
Just add the following rule to your <system.webServer> section:
<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
<modules runAllManagedModulesForAllRequests="true" />
<rewrite>
<rules>
<rule name="Rewrite to index.html">
<match url="^(?:(?!api\/))" />
<action type="Rewrite" url="index.html" />
</rule>
</rules>
</rewrite>
<handlers>
<remove name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" />
<remove name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" />
<remove name="ExtensionlessUrlHandler-Integrated-4.0" />
<add name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness32" responseBufferLimit="0" />
<add name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness64" responseBufferLimit="0" />
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
</handlers>
</system.webServer>
Also since you are not using ASP.NET MVC you could get rid of the ~/App_Start/RouteConfig.cs file because you don't have any MVC controllers. Just keep the ~/App_Start/WebApiConfig.cs where you will have a route for the ~/api endpoint mapped to your Web API controllers:
public static class WebApiConfig
{
public static void Register(HttpConfiguration config)
{
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
}
}

publish asp.net mvc 4 site gave 404 on IIS 6 host

Newly created ASP.Net MVC 4, C# project with VS Express 2012 for Web, target .Net Framework version 4.0 (same as the remote host).
Debugging directly through VS is find. After publishing to local folder, [original:There is no .aspx generated, only sitename.dll, there were even original .cshtml files] and copying to IIS Express C:\inetpub\www folder, http://localhost/Home is fine.
But when I upload everything to host (according to info.aspx, server info: IIS 6.0, .Net Version 4.0.30319.239), http://domain/Home gave page cannot be found 404 error, which seems like a routing problem.
Here is my Web.config:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=4.4.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<connectionStrings>
<add name="DefaultConnection" connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=aspnet-FireupCooking.Net4._0-20130620031747;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnet-FireupCooking.Net4._0-20130620031747.mdf" providerName="System.Data.SqlClient" />
</connectionStrings>
<appSettings>
<add key="webpages:Version" value="2.0.0.0" />
<add key="webpages:Enabled" value="false" />
<add key="PreserveLoginUrl" value="true" />
<add key="ClientValidationEnabled" value="true" />
<add key="UnobtrusiveJavaScriptEnabled" value="true" />
</appSettings>
<system.web>
<customErrors mode="Off" />
<compilation targetFramework="4.0" />
<authentication mode="Forms">
<forms loginUrl="~/Account/Login" timeout="2880" />
</authentication>
<pages>
<namespaces>
<add namespace="System.Web.Helpers" />
<add namespace="System.Web.Mvc" />
<add namespace="System.Web.Mvc.Ajax" />
<add namespace="System.Web.Mvc.Html" />
<add namespace="System.Web.Optimization" />
<add namespace="System.Web.Routing" />
<add namespace="System.Web.WebPages" />
</namespaces>
</pages>
</system.web>
<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
<modules runAllManagedModulesForAllRequests="true" />
<handlers>
<remove name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" />
<remove name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" />
<remove name="ExtensionlessUrlHandler-Integrated-4.0" />
<add name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness32" responseBufferLimit="0" />
<add name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness64" responseBufferLimit="0" />
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
</handlers>
</system.webServer>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
</entityFramework>
</configuration>
Here are the files under bin/:
Antlr3.Runtime.dll
DotNetOpenAuth.AspNet.dll
DotNetOpenAuth.Core.dll
DotNetOpenAuth.OAuth.Consumer.dll
DotNetOpenAuth.OAuth.dll
DotNetOpenAuth.OpenId.dll
DotNetOpenAuth.OpenId.RelyingParty.dll
EntityFramework.dll
FireupCooking.Net4.0.dll
Microsoft.Web.Infrastructure.dll
Microsoft.Web.WebPages.OAuth.dll
Newtonsoft.Json.dll
System.Net.Http.dll
System.Net.Http.Formatting.dll
System.Net.Http.WebRequest.dll
System.Web.Helpers.dll
System.Web.Http.dll
System.Web.Http.WebHost.dll
System.Web.Mvc.dll
System.Web.Optimization.dll
System.Web.Razor.dll
System.Web.WebPages.Deployment.dll
System.Web.WebPages.dll
System.Web.WebPages.Razor.dll
WebGrease.dll
WebMatrix.Data.dll
WebMatrix.WebData.dll
I also tried the following minimal web.config, info.aspx still gave the Server Application Unavailable error. UPDATE: This file now showing server info.
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.web>
<customErrors mode="Off" />
</system.web>
</configuration>
Static files html, gif and simple *.aspx*s are fine. Only MVC pathes /Home/Index and /Home gave 404 - not found error.
What should I change to make it work?
What you got on the local side is correct. .Csthml files are the web pages when using Razor.
Did you set up IIS correctly on the Host? You have to create a website and make sure that the Application pool is using the correct .Net Version.
Using ASP.NET MVC with Different Versions of IIS (C#) had it step by step for shared host IIS 6 to use MVC routing. It was even on the VS generated page, but I had ignored it.
So for anyone else having the similar headache, here is important parts.
1. Assuming it is a shared host that we can't do much server config.
2. IIS 6, .Net 4.0, and possibly Windows 2003
In our Asp.Net MVC 4, global.asax.cs register routs
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"Default",
"{controller}.aspx/{action}/{id}",
new { action = "Index", id = "" }
);
routes.MapRoute(
"Root",
"",
new { controller = "Home", action = "Index", id = "root" }
);
}
protected void Application_Start()
{
RegisterRoutes(RouteTable.Routes); //RouteConfig.RegisterRoutes didn't work
}
Since .aspx files are directed to ASP.Net for processing, these routing rules will catch http://domain/home.apspx/index to invoke HomeController.Index.
If there is a need to ignore some files, just prepend a ignoring rule like below
routes.IgnoreRoute("Content/{*pathInfo}");
routes.IgnoreRoute("info.aspx");
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");