Visual studio 2013 view project in browser gives internal server error - iis

I am new with Visual studio 2013 and I am currently working on two projects started by another developer. With one project the view option works fine using IIS Express, but the second one gives me error 500 with the below details...
"HTTP Error 500.19 - Internal Server Error. The requested page cannot be accessed because the related configuration data for the page is invalid."
"Config Error: Cannot add duplicate collection entry of type 'add' with unique key attribute 'name' set to 'Access-Control-Allow-Origin'"
Config Source:
<customHeaders>
<add name="Access-Control-Allow-Origin" value="*" />
<add name="Access-Control-Allow-Headers" value="Content-Type" />
Hope somebody knows about an error like this and how I can solve it. Thanx in advance

I suspect IIS is already sending an Access-Control-Allow-Headers by default and that is blowing up.
Typically when setting custom headers one usually does a prophalactic removal first:
<customHeaders>
<remove name="Access-Control-Allow-Origin" />
<remove name="Access-Control-Allow-Headers" />
<add name="Access-Control-Allow-Origin" value="*" />
<add name="Access-Control-Allow-Headers" value="Content-Type" />
</customHeaers>
This insures your app works no matter what happened upstream in configuration.

Related

Error : The resource you are looking for has been removed, had its name changed, or is temporarily unavailable

Offlate almost every website/api service/mobile service I deploy, When I hit any route apart from default one, I get the following error 'The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.'
For testing I created a simple ASP.Net WebAPI app and ASP.Net MVC Website and deployed to Azure. It gets deployed and default pages come up. For any link after that, I get that error.
Below is the mobile service.. created and uploaded without modification and configured facebook authentication on portal.azure.com https://wayweb.azurewebsites.net/.auth/login/facebook/callback
Copy of code is at https://1drv.ms/u/s!AkQ9G9AdaYOPgaZ-vXUdlSW9RuQzOQ
Any idea, what am I doing wrong?
Add web.config file to your azure directory. Add the code below into it.
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Main Rule" stopProcessing="true">
<match url=".*" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="/" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
If you can't open a json file or any other file even though it exists, try to add:
<system.webServer>
<staticContent>
<mimeMap fileExtension=".woff2" mimeType="application/x-font-woff" />
<mimeMap fileExtension=".woff" mimeType="application/x-font-woff" />
<mimeMap fileExtension=".json" mimeType="application/json" />
</staticContent>
It could help:
To remedy the problem, you need to provide a web.config file into your Angular 2 application.
https://hgminerva.wordpress.com/2016/04/27/hosting-angular-2-in-windows-azure-error-the-resource-you-are-looking-for-has-been-removed-had-its-name-changed-or-is-temporarily-unavailable/
For me this error had occurred when I did runAllManagedModulesForAllRequests="false"
<modules runAllManagedModulesForAllRequests="true">
<add type="DevExpress.Web.ASPxHttpHandlerModule, DevExpress.Web.v20.1, Version=20.1.4.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" name="ASPxHttpHandlerModule" />
<remove name="FormsAuthentication" />
<remove name="DefaultAuthentication" />
<remove name="OutputCache" />
<remove name="AnonymousIdentification" />
<remove name="RoleManager" />
</modules>
Security Audit - my security auditor asked me to removed
Physical Path C:\Users\Dell\Documents\Development\WebServicePortal\PyWebServicePortal\Dashboard\DashboardView\robots.txt
I was getting 404 (The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.), I wanted to use custom error if resource code found.
I've used following code:
<httpErrors errorMode="Custom" existingResponse="Auto" defaultResponseMode="File" >
<remove statusCode="404"/>
<error statusCode="404" path="ErrorPages/Oops.html" />
</httpErrors>
This is the same message error related to a problem with versioning issues of System.Net.Http.dll, System.Net.Http.Formating.dll and System.Net.Http.WebRequest.dll. I fixed that posting those assemblies in the bin folder of my Azure Web API, even though they were supposed been used from global cache. You can see details in ASP Web API not working in Azure
I tried all of the above options, none could resolve my issue.
I resolved it by adding the web.config file into my src folder and injecting it from the package.json file.
"tsConfig": "tsconfig.app.json",
"aot": true,
"assets": [
"src/favicon.ico",
"src/assets",
**"src/web.config"**
],

Enable cross site access in OK Hosting?

I'm trying to download the bootsrap fonts from a container I have in a site hosted by OK Hosting. I can download the font manually but when using it in a CSS on a page hosted in another server, it fails because cross site access is disabled.
I know OK Hosting uses IIS but they give you a web based control panel.
How do I enable cross site access?
Ok, you just have to add a file called web.config at the root of your site with the following:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Origin" value="*" />
</customHeaders>
</httpProtocol>
</system.webServer>
</configuration>
You might also need the following just below the Access-Control-Allow-Origin.
<add name="Access-Control-Allow-Methods" value="GET,PUT,POST,DELETE,OPTIONS" />
<add name="Access-Control-Allow-Headers" value="Content-Type" />

Remove cache HTTP response headers from Web Api in Azure

I am trying to remove unwanted Cache-Control, Pragma and Expires HTTP headers in responses from a Web Api 2 project hosted on an Azure website in Standard mode.
I have tried the following in Global.asax Application_PreSendRequestHeaders:
var headers = ((HttpApplication)sender).Context.Response.Headers;
headers.Remove("Cache-Control");
headers.Remove("Pragma");
headers.Remove("Expires");
This works when debugging in Visual Studio. But on Azure, the headers are only removed for GET requests and not HEAD or POST requests.
Grateful for any suggestions!
Azure Web Sites supports the request filtering module, so you can do this in your web.config:
<system.webServer>
<httpProtocol>
<customHeaders>
<remove name="Cache-Control" />
<remove name="Pragma" />
<remove name="Expires" />
</customHeaders>
</httpProtocol>
</system.webServer>
Disclaimer: I am not condoning the removal of these headers, which are an essential part of the HTTP protocol.
Removing cache headers says to clients "it is entirely up to you to decide how to cache this response", which may result in odd and hard-to-reproduce errors in production. If you want to disable caching, you should set these headers to values which explicitly disable caching:
<system.webServer>
<httpProtocol>
<customHeaders>
<add name="Cache-Control" value="no-cache" />
<add name="Pragma" value="no-cache" />
<add name="Expires" value="-1" />
</customHeaders>
</httpProtocol>
</system.webServer>

CS0104: 'Scripts' is an ambiguous reference between 'System.Web.WebPages.Scripts' and 'System.Web.Optimization.Scripts'

My project is on MVC 4.
In it I can't access any of scripts function like #Scripts.Render("~/bundles/modernizr") as Scripts is an ambigious reference between 'System.Web.WebPages.Scripts' and 'System.Web.Optimization.Scripts'
I have following entries in my webconfig :
<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"/>
<add namespace="Product360"/>
</namespaces>
</pages>
I updated System.web.optimization from package manager console, still it's showing me same error.
I can't figure out why it's intellisensing in System.web.WebPages instead of System.web.optimization.
Anyone has any updates on this?
Do you use WebMaxtrix / Web Pages or only ASP.NET MVC? If you're only using MVC get rid of this line
<add namespace="System.Web.WebPages"/>
And you shouldn't have a conflict anymore.
Note: you might need to restart Visual Studio for the namespaces to be handled properly in the cshtml files after the modification.

Implementing BlogEngine as an application within Umbraco

I have an installation of Umbraco v4.9.0 within which I am trying to get a working install of BlogEngine.NET v2.6.0.5
This is in IIS8 on a Windows 8 machine.
I have so far been able to set up BlogEngine within a sub folder and the application works just fine until I try to open a page with the cshtml extension.
The error i am getting is
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: /blog/admin/default.cshtml
Both web.configs have entries designed to prevent this error from happening.
Umbraco
<buildProviders>
<add extension=".cshtml"
type="umbraco.MacroEngines.RazorBuildProvider, umbraco.MacroEngines" />
<add extension=".vbhtml"
type="umbraco.MacroEngines.RazorBuildProvider, umbraco.MacroEngines" />
<add extension=".razor"
type="umbraco.MacroEngines.RazorBuildProvider, umbraco.MacroEngines" />
</buildProviders>
BlogEngine
<buildProviders>
<remove extension=".cshtml" />
<add extension=".cshtml"
type="System.Web.WebPages.Razor.RazorBuildProvider, System.Web.WebPages.Razor"/>
</buildProviders>
I have the relevant MVC binaries in the respective bin folders and I've even tried adding request filtering instructions to both web.configs e.g
<requestFiltering>
<fileExtensions>
<add fileExtension=".cshtml" allowed="true" />
</fileExtensions>
</requestFiltering>
Have I missed something obvious?
Is your IIS site running in Classic or Integrated mode? Try switching to Integrated mode and see if that fixes your issue.

Resources