Publish Web Api (MVC 4) - asp.net

I built a REST API following this tutorial and this one, and when I run application from Visual Studio 2012 things seem to work properly.
The problem is when I publish (to file system), I get a new folder under wwwroot and some files are placed there, but when I try to access http://localhost:82/my_published_api/ I only see a list of what seems useless files, http://localhost:82/my_published_api/api/ throws a 404 as does http://localhost:82/my_published_api/api/contact/ which is actually working from VStudio.
Am I missing something? What do I need to publish to a directory and access api modules?
EDIT some extra info:
This is system.web section in Web.Config:
<system.web>
<httpRuntime/>
<compilation debug="true" targetFramework="4.0"/>
<pages controlRenderingCompatibilityVersion="4.0">
<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.Routing"/>
<add namespace="System.Web.WebPages"/>
</namespaces>
</pages>
</system.web>
And pre-production published version is running in http://localhost:82/my_published_api/ (this is the one which throws 404) while Visual Studio runtime server runs in http://localhost:51976/api/contact/ (this one runs properly)
Pre-production site is IIS under Windows 7, real production site will be a Windows server 2003.
Thank you

Related

.NET 4.0 DataAnnotations GAC/EntityFramework conflict

I'm trying to build an ASP.NET web site for Microsoft .NET 4.0 using Entity Framework 6. The website is explicitly targetting .NET 4.0 in web.config:
<compilation debug="true" targetFramework="4.0">
, IIS Express' application pool in applicationhost.config also targets .NET 4.0:
<add name="Clr4ClassicAppPool" managedRuntimeVersion="v4.0" managedPipelineMode="Classic" CLRConfigFile="%IIS_USER_HOME%\config\aspnet.config" autoStart="true" />
When the site is launched, a number of CS0433 compiler errors is shown, ones like below:
error CS0433: The type "System.ComponentModel.DataAnnotations.Schema.TableAttribute" exists in both "c:\Windows\Microsoft.NET\assembly\GAC_MSIL\System.ComponentModel.DataAnnotations\v4.0_4.0.0.0__31bf3856ad364e35\System.ComponentModel.DataAnnotations.dll" and "c:\Users\%username%\AppData\Local\Temp\Temporary ASP.NET Files\vs\e798ee36\2b3f5a24\assembly\dl3\fd34a92a\0052703a_0990d101\EntityFramework.DLL"
As far as I remember, there should be no System.ComponentModel.DataAnnotations assembly in .NET 4.0, or at the very least it shouldn't contain classes like TableAttribute, KeyAttribute etc. The only lead I have is the bottom line of error page, which says
Microsoft .NET Framework, version:4.0.30319; ASP.NET, version:4.6.1055.0
however, I don't know how to change specifically ASP.NET version for a website (of course, if that's the problem's source).
Have you tried setting the compilation batch to false?
<compilation debug="false" batch="false">
I'm assuming you've got code in your App_Code folder (likely your Entity Framework classes at the least?).
Now you could move your code out of there, and precompile everything so that you deploy the website assembly and not any source files.
Otherwise, you really need to look at your projects and ensure that nothing is referencing System.ComponentModel.DataAnnotations.
Also, check any web.config in the project at the root, or in the App_Code folder(s) and make sure there is no
<add assembly="System.ComponentModel.DataAnnotations, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
under system.web/compilation/assemblies. If there isn't, you could even try putting in
<remove assembly="System.ComponentModel.DataAnnotations, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
e.g.:
<compilation>
<assemblies>
<remove assembly="System.ComponentModel.DataAnnotations, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
</assemblies>
</compilation>
You can also check to make sure it's running the earlier version of ASP.NET so that it picks up the version of the DataAnnotations assembly that doesn't have the Schema attribute (as the 4.5+ framework version does):
<configuration>
<system.web>
<httpRuntime targetFramework="4.0" />
</system.web>
</configuration>
Hey Can you check your project.Please check there should not be two model with same properties.Model can also be entity framework class model
Check if all NuGet packages for your project are updated or if there are any installed that you don't want.

500.21 Bad module "ManagedPipelineHandler" in its module list

I am getting the error:
HTTP Error 500.21 - Internal Server Error
Handler "CloudConnectHandler" has a bad module "ManagedPipelineHandler" in its module list
my web.config file looks like this:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<handlers>
<add name="CloudConnectHandler" verb="*" path="CloudConnect.aspx" type="CloudConnectHandler" resourceType="Unspecified" />
</handlers>
</system.webServer>
<system.web>
<customErrors mode="Off" />
<compilation debug="true" targetFramework="4.0" batch="false">
<assemblies>
<add assembly="System.Xml.Linq, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
<add assembly="System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
<add assembly="Microsoft.CSharp, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A" />
</assemblies>
</compilation>
<pages>
<controls>
<add tagPrefix="ajaxToolkit" assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" />
</controls>
</pages>
<identity impersonate="true" />
<authentication mode="Forms" />
</system.web>
<system.codedom>
<compilers>
<compiler language="c#;cs;csharp" extension=".cs" warningLevel="4" type="Microsoft.CSharp.CSharpCodeProvider, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<providerOption name="CompilerVersion" value="v4.0" />
<providerOption name="WarnAsError" value="false" />
</compiler>
</compilers>
</system.codedom>
<appSettings>
<add key="CloudConnectAuthorization" value="xxxx" />
<add key="ConnectionInfo" value="xxxx" />
<add key="ConnectionString" value="xxxx" />
<add key="DefaultChannel" value="xxxx" />
<add key="LoginValidationConnectionString" value="xxxx" />
</appSettings>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="protobuf-net" publicKeyToken="257b51d87d2e4d67" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.0.0.640" newVersion="2.0.0.640" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
There is a lot of advice out there indicating that asp.net is not installed correctly. The usual fix is to run:
%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_regiis.exe -i
or
%windir%\Microsoft.NET\Framework\v4.0.21006\aspnet_regiis.exe -i
I have run both, without any errors. I have restarted IIS, but the problem still persists. The site is using an application pool. The app pool is started, .net framework = 4.0, Managed Pipeline = Classic, Identity = LocalSystem.
I've spent the last couple hours trying to figure out what the problem is. I'm hoping someone can help.
Please follow these steps:
1) Run the command prompt as administrator.
2) Type either of the two lines below in the command prompt:
%windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_regiis.exe -i
or
%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_regiis.exe -i
I ran into this error on a fresh build of Windows Server 2012 R2. IIS and .NET 4.5 had been installed, but the ASP.NET Server Role (version 4.5 in my case) had not been added. Make sure that the version of ASP.NET you need has been added/installed like ASP.NET 4.5 is in this screenshot.
To fix the problem, I tried to run
%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_regiis.exe -i
However It didn't work for me. I have to run another command line in CMD window as administrator. Here is the command:
dism /online /enable-feature /featurename:IIS-ASPNET45
or
dism /online /enable-feature /featurename:IIS-ASPNET45 /all
Hope it will help.
Try switching to Integrated mode. See the following thread:
IIS 7, HttpHandler and HTTP Error 500.21
I got this error on my ASP.Net 4.5 app on Windows Server 2012 R2.
Go to start menu -> "Turn windows features on or off". A wizard popped up for me.
Click Next to Server Roles
I had to check these to get this to work, located under Web Server IIS->Web Server-> Application Development (these are based on Jeremy Cook's answer above):
Then click next to Features and make sure the following is checked:
Then click next and Install. At this point, the error went away for me. Good luck!
This is because IIS 7 uses http handlers from both <system.web><httpHandlers> and <system.webServer><handlers>. if you need CloudConnectHandler in your application, you should add <httpHandlers> section with this handler to the <system.web>:
<httpHandlers>
<add verb="*" path="CloudConnect.aspx" type="CloudConnectHandler" />
</httpHandlers>
and also add preCondition attribute to the handler in <system.webServer>:
<handlers>
<add name="CloudConnectHandler" verb="*" path="CloudConnect.aspx" type="CloudConnectHandler" preCondition="integratedMode" />
</handlers>
Hope it helps
I had this issue in Windows 10 when I needed IIS instead of IIS Express. New Web Project failed with OP's error. Fix was
Control Panel > Turn Windows Features on or off > Internet Information Services > World Wide Web Services > Application Development Features
tick ASP.NET 4.7 (in my case)
For me, I was getting this error message when using PUT or DELETE to WebAPI. I also tried re-registering .NET Framework as suggested but to no avail.
I was able to fix this by disabling WebDAV for my individual application pool, this stopped the 'bad module' error when using PUT or DELETE.
Disable WebDAV for Individual App Pool:
Click the affected application pool
Find WebDAV Authoring Tools in the list
Click to open it
Click Disable WebDAV in the top right.
This link is where I found the instructions but it's not very clear.
I had this problem every time I deployed a new website or updated an existing one using MSDeploy.
I was able to fix this by unloading the app domain using MSDeploy with the following syntax:
msdeploy.exe -verb:sync -source:recycleApp -dest:recycleApp="Default Web Site/myAppName",recycleMode=UnloadAppDomain
You can also stop, start, or recycle the application pool - more details here: http://technet.microsoft.com/en-us/library/ee522997%28v=ws.10%29.aspx
While Armaan's solution helped get me unstuck, it did not make the problem go away permanently.
if it is IIS 8 go to control panel, turn windows features on/off and enable Bad "Named pipe activation" then restart IIS. Hope the same works with IIS 7
I discovered that the order of adding roles and features is important.
On a fresh system I activate the role "application server" and there check explicitly .net, web server support and finally process activation service
Then automatically a dialogue comes up that the role "Web server" needs to be added also.
Install .NET framework as below, it will work .NET version 4.5 as well.
%windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_regiis.exe -ir
Some time only give aspnet_regiis.exe -i don't work so give aspnet_regiis.exe -ir in above path.

Server Error in '/' Application. This type of page is not served

I have an host where I hosted a webpage with .cshtml extension. My host is arvixe.com that provides ASP and .NET hosting but when I try to load my web page I get this error message.
Server Error in '/' Application.
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.
Requested URL: /samples/WoT/Default.cshtml
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.276
I read something does I have to write something in my web.config file to make it work
like this
<compilation>
<assemblies>
<add assembly="System.Web.WebPages.Razor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
</assemblies>
<buildProviders>
<add extension=".cshtml" type="System.Web.WebPages.Razor.RazorBuildProvider, System.Web.WebPages.Razor"/>
</buildProviders>
</compilation>
But I tried everything, paste it in on different lines, nothing worked. What do I miss or do wrong?
I believe you are not making using the MVC feature and trying to load just the razor view outside views or custom Area folders.
Then you need to enable webpages key in Web.config which is disabled by default in .Net 4.0
<add key="webpages:Enabled" value="true" />
<appSettings>
<add key="webpages:Enabled" value="true" />
Repairing this in Windows 10 Pro using IIS 10 was a nightmare, it took two days but I was finally able to achieve the desired results using the following procedure:
Open your web site in Visual Studio. The way you do this is to go to File > New > Web Site and then select ASP.Net Empty Web Site AND before you click OK change the location to your project location. In my case I had my project in C:\inetpub\wwwroot\AspNet\Projects\Test
Open internet information services manager (click the "cortana" search and type IIS, it should show up as long as you have it installed). Locate your project folder under the ServerName > Sites > Default Web Site > ... , right click on it and click the "Convert to web Application" button. Accepting the defaults at the prompt by clicking OK should be sufficient in most cases.
Use the following Web.Config file, or something similar. NuGet may overwrite some settings but this isn't a big problem.
<?xml version="1.0" encoding="utf-8"?>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=301879
-->
<configuration>
<appSettings>
<add key="webPages:Version" value="3.0.0"/>
<add key="webpages:Enabled" value="true"/>
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.0"/>
</system.web>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
</assemblyBinding>
</runtime>
</configuration>
Delete your bin folder, and packages.config file, if they exist. This is because we must assume that something in that bin folder is corrupt since IIS is designed to run Razor/ASP. In your visual studio project you will need to refresh your project so it knows these files have been deleted. This can be done by clicking the refresh button in the menu on the top of the Solution Explorer frame. In you visual studio project go to Tools > NuGet Package Manager > Package Manager Console and enter the following two commands.
Install-Package Microsoft.AspNet.Razor -Version 3.0.0
Install-Package Microsoft.AspNet.WebPages
This was enough to get *.cshtml pages to be rendered by IIS 10 on Windows 10 Pro.

HTTP Error 500.22 - Internal Server Error (An ASP.NET setting has been detected that does not apply in Integrated managed pipeline mode.)

I receive this error when I view an application.
HTTP Error 500.22 - Internal Server Error (An ASP.NET setting has been detected that does not apply in Integrated managed pipeline mode.)
.Net framework 2.0, 3.5 and 4 are installed and I am using SQL 2008. Can anyone tell me what the solution is for this error?
This issue is caused by the pipeline mode in your Application Pool setting that your web site is set to.
Short
Simple way Change the Application Pool mode to one that has Classic pipeline enabled.
Correct way Your web.config / web app will need to be altered to support Integrated pipelines. Normally this is as simple as removing parts of your web.config.
Simple way (bad practice) Add the following to your web.config. See http://www.iis.net/ConfigReference/system.webServer/validation
<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
</system.webServer>
Long
If possible, your best bet is to change your application to support the integrated pipelines. There are a number of changes between IIS6 and IIS7.x that will cause this error. You can find details about these changes here http://learn.iis.net/page.aspx/381/aspnet-20-breaking-changes-on-iis-70/.
If you're unable to do that, you'll need to change the App pool which may be more difficult to do depending on your availability to the web server.
Go to the web server
Open the IIS Manager
Navigate to your site
Click Advanced Settings on the right Action pane
Under Application Pool, change it to an app pool that has classic enabled.
Check http://technet.microsoft.com/en-us/library/cc731755(WS.10).aspx for details on changing the App Pool
If you need to create an App Pool with Classic pipelines, take a look at http://technet.microsoft.com/en-us/library/cc731784(WS.10).aspx
If you don't have access to the server to make this change, you'll need to do this through your hosting server and contact them for help.
Feel free to ask questions.
In your web.config, make sure these keys exist:
<configuration>
<system.webServer>
<validation validateIntegratedModeConfiguration="false"/>
</system.webServer>
</configuration>
I changed my web.config file to use HTTPMODULE in two forms:
IIS: 6
<httpModules>
<add name="Module" type="app.Module,app"/>
</httpModules>
IIS: 7.5
<system.webServer>
<modules>
<add name="Module" type="app.Module,app"/>
</modules>
</system.webServer>
Using VS2013 .net 4.5
I had this same issue.
The "Most likely causes" section on the error message page provided the most help. For me. It said "This application defines configuration in the system.web/httpModules section." Then in the "Things you can try" section it said "Migrate the configuration to the system.webServer/modules section."
<system.web>
<httpHandlers>
<add type="DevExpress.Web.ASPxUploadProgressHttpHandler, DevExpress.Web.v15.1, Version=15.1.4.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" verb="GET,POST" path="ASPxUploadProgressHandlerPage.ashx" validate="false" />
<add type="DevExpress.Web.ASPxHttpHandlerModule, DevExpress.Web.v15.1, Version=15.1.4.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" verb="GET" path="DX.ashx" validate="false" />
</httpHandlers>
<httpModules>
<add type="DevExpress.Web.ASPxHttpHandlerModule, DevExpress.Web.v15.1, Version=15.1.4.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" name="ASPxHttpHandlerModule" />
</httpModules>
</system.web>
into the system.webServer section.
<system.webServer>
<handlers>
<add type="DevExpress.Web.ASPxUploadProgressHttpHandler, DevExpress.Web.v15.1, Version=15.1.4.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" verb="GET,POST" path="ASPxUploadProgressHandlerPage.ashx" name="ASPxUploadProgressHandler" preCondition="integratedMode" />
<add type="DevExpress.Web.ASPxHttpHandlerModule, DevExpress.Web.v15.1, Version=15.1.4.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" verb="GET" path="DX.ashx" name="ASPxHttpHandlerModule" preCondition="integratedMode" />
</handlers>
<modules>
<add type="DevExpress.Web.ASPxHttpHandlerModule, DevExpress.Web.v15.1, Version=15.1.4.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" name="ASPxHttpHandlerModule" />
</modules>
</system.webServer>
This worked for me:
Delete the originally created site.
Recreate the site in IIS
Clean solution
Build solution
Seems like something went south when I originally created the site. I hate solutions that are similar to "Restart your machine, then reinstall windows" without knowing what caused the error. But, this worked for me. Quick and simple. Hope it helps someone else.
I have a similar problem with IIS 7, Win 7 Enterprise Pack. I have changed the application Pool as in #Kirk answer :
Change the Application Pool mode to one that has Classic pipeline enabled".but no luck for me.
Adding one more step worked for me.
I have changed the my website's .NET Frameworkis v2.0 to .NET Frameworkis v4.0. in ApplicationPool
Personnaly I encountered this issue while migrating a IIS6 website into IIS7, in order to fix this issue I used this command line :
%windir%\System32\inetsrv\appcmd migrate config "MyWebSite\"
Make sure to backup your web.config
Set Application pool to classic .NET appool and make sure that Classic .Net apppool working on Classic managed piple line .

Mapping classic asp pages to .net in IIS

I'm trying to map requests for classic asp pages to be handled by .net, so that it runs through a custom httpmodule.
In IIS I have remapped asp requests to aspnet_isapi.dll - I'm sure I've done this bit right
Now in my test app I am getting this error:
Server Error in '/TestASPRedirect' Application.
--------------------------------------------------------------------------------
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 '.asp' may be incorrect. Please review the URL below and make sure that it is spelled correctly.
Requested URL: /testaspredirect/test.asp
Searching online for this error shows a load of people having problems with cassini, but this is not really relevant, I am testing this on both IIS 5.1 on XP dev machine, and have tested on IIS6 also getting the same error.
I have followed instructions for adding and registering a httphandler (see http://support.microsoft.com/default.aspx?scid=kb;en-us;Q308001), but I don't know what to put in the ProcessRequest routine to ensure the request gets passed on. What is the default .net httphandler, can I just map to this in web.config?: so something like:
<httpHandlers>
<add verb="*" path="*.asp" type="standard.nethttphandler"/>
</httpHandlers>
How do I tell asp.net that it needs to pass ASP requests on and not block?
Actually you are only one step far from the success. Adding following section to your Local website(or virtual directory) web.config file:
<configuration>
...
<system.web>
<compilation>
<buildProviders>
<add extension=".asp" type="System.Web.Compilation.PageBuildProvider"/>
</buildProviders>
</compilation>
<httpHandlers>
<add path="*.asp" verb="*" type="System.Web.UI.PageHandlerFactory" validate="true"/>
</httpHandlers>
</system.web>
It looks like the .asp extension is mapped to the HttpForbiddenHandler.
If you're using ASP.NET 1.1 then open the following file:
C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\CONFIG\machine.config
If you're using ASP.NET 2.0 then open this file:
C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\CONFIG\web.config
Search for "path="*.asp"", then comment out that line. It'll like something like:
<!-- machine.config/ASP.NET 1.1-->
<add path="*.asp" verb="*"
type="System.Web.HttpForbiddenHandler"/>`
<!-- web.config/ASP.NET 2.0-->
<add path="*.asp" verb="*"
type="System.Web.HttpForbiddenHandler" validate="true"/>`
Locate the below file:
C:\WINDOWS\MICROSOFT.NET\FRAMEWORK\<FramworkVersion>\Config\web.config
where <FramworkVersion> is folder name:
open it in an XML editor .. (even notepad is fine)
and add below line :
<add path="*.asp" verb="*" type="System.Web.UI.PageHandlerFactory" validate="True"/>
under below XPath:
configuration/system.web/httpHandlers
replace the existing one!
Add below line:
<add extension=".asp" type="System.Web.Compilation.PageBuildProvider"/>
under below XPath:
/configuration/system.web/compilation/buildProviders
Worked like gem for me :)

Resources