Swagger not supporting minor versions ASP.NET Webapi - asp.net-web-api2

I am developing a webapi which supports multiple versions. Currently I have three versions 1.0, 1.1 and 2.0. I have gone through the solution for multi version support in swagger and implemented it from the below link
swagger not working properly with multiversions
The code works fine but the problem is swagger is not loading with version 1.1. It works fine with version 1.0 and 2.0.
Thanks in advance.

Figured out the solution. It's due to swagger.config instance problem. Solved by adding the assembly [assembly: PreApplicationStartMethod(typeof(SwaggerConfig), "Register")] in swagger.config and moved all the versioning code to webapi.config. Not sure why this has to be done for minor versions to work but it worked for me.

For me, http://localhost:64754/swagger/docs/v1.1 would return a 404 error while http://localhost:64754/swagger/docs/v1 or http://localhost:64754/swagger/docs/v2 worked fine.
The way I fixed it was to add this to the web.config:
<system.webServer>
<modules>
<remove name="UrlRoutingModule-4.0" />
<add name="UrlRoutingModule-4.0" type="System.Web.Routing.UrlRoutingModule" preCondition="" />
</modules>
...
</system.webServer>

Related

Could not load file or assembly 'Microsoft.AspNet.Web.Optimization.WebForms' or one of its dependencies. The system cannot find the file specified

I can't find anything to resolve this and have tried multiple things.
Task: I am trying to add bundles to an old existing web project. I have added everything I need I believe as I have done the same in a new project and it works.
<webopt:BundleReference runat="server" Path="~/bundles/masterstyle" />
This seems to be where the issue has started with this line above. I installed via nuget the web optimization webforms package which fixed the squiggly line under webopt. However, now, I am getting 2 issues.
BundleReference has a squiggly line saying "Element
'BundleReference' is not a known element/ This can occur if there is
a complication error in the Web site, or the web.config file is
missing".
It also can't seem to find the package I have just installed which
is "Could not load file or assembly
'Microsoft.AspNet.Web.Optimization.WebForms' or one of its
dependencies. The system cannot find the file specified".
If anyone can help resolve this, it would be greatly appreciated. Been stuck on it for 4 hours now.
Here is the likely relevant stuff in my web.config file:
<pages>
<namespaces>
<add namespace="System.Web.Optimization"/>
</namespaces>
<tagMapping>
<add tagType="System.Web.UI.HtmlControls.HtmlForm" mappedTagType="we3.Site.Form" />
</tagMapping>
<controls>
<add assembly="Microsoft.AspNet.Web.Optimization.WebForms" namespace="Microsoft.AspNet.Web.Optimization.WebForms" tagPrefix="webopt"/>
</controls>
</pages>
<compilation debug="true" strict="false" explicit="true" targetFramework="4.0" />
Install it from nugget: https://www.nuget.org/packages/Microsoft.AspNet.Web.Optimization.WebForms/
Install-Package Microsoft.AspNet.Web.Optimization.WebForms
Or you can manually download it from: https://www.nuget.org/api/v2/package/Microsoft.AspNet.Web.Optimization.WebForms/1.1.3
and add it as reference to your project (unzip first the .nupkg file)
Installing the package Microsoft.AspNet.Web.Optimization is what resolved this for me.
Install-Package Microsoft.AspNet.Web.Optimization

No transpilation on IIS production server

First off, a lot of this technology is new to me, so I apologize for the noob question. Also, this is my first post to SO (after years of reading), so forgive the formatting.
I have a web application that I am running via MSVS 2017. I am writing my front end with React.js. After installing the appropriate packages via nuget, I have something that works when I run both the debug and release versions on my local dev machine (using iisexpress).
However, after I commit my source changes, and it gets pushed to the test server (IIS), the app runs fine. But, the JSX files that are returned from the test server are not transpiled. I just get the raw JSX file. Whereas, on my local machine, the returned file is transpiled.
I have a ReactConfig.cs file with a single static Configure method, where I have a call to add my JSX file via ReactSiteConfiguration.Configuration.AddScript, but that appears to be unnecessary because I still get a transpiled result even when it is commented out. At the top of my ReactConfig.cs file I have seomthing similar to:
[assembly: webActivatorEx.PreApplicationStartMethod(typeof(MyApp.Api.Controllers.MyController), "AutoMapperStart")]
So, then I am left with the question of how is the transpiling occuring on my dev machine, but not the deployment machine.
In my web.config file, I have tried both:
<httpHandlers>
<add verb="GET" path="*.jsx" type="React.Web.BabelHandlerFactory, React.Web" />
</httpHandlers>
and
<remove name="Babel" /><add name="Babel" verb="GET" path="*.jsx" type="React.Web.BabelHandlerFactory, React.Web" preCondition="integratedMode" /></handlers>
But neither seems to make a difference on the deployed server.
If anyone has suggestions of what I should look at next, it would be greatly appreciated.
Update:
I notice the relevant item that is allowing my dev environment to do the transpilation is the second code section above in my web.config file. However, that I don't see the same lines on the server. Are web.config file typically 'hand edited' per deployment, perhaps?
So, here is what I eventually figured out that worked for me.
First, yes, the web.config file is deployed with as a template. And then hand configured as necessary.
Second, and more importantly, there are two parts to getting the server to render JSX to pure JS.
I needed the following in the web.config file:
<system.webServer>
<handlers>
<remove name="Babel" />
<add name="Babel" verb="GET" path="*.jsx"
type="React.Web.BabelHandlerFactory, React.Web"
preCondition="integratedMode"/>
</handlers>
</system.webServer>
And finally, in the assemblyBinding section:
<dependentAssembly>
<assemblyIdentity name="JavaScriptEngineSwitcher.Core" publicKeyToken="c608b2a8cc9e4472" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.4.9.0" newVersion="2.4.9.0" />
</dependentAssembly>

The key 'LocalizedPerfCounter' does not exist in the appSettings configuration section

I have a desktop application coded in VB.Net with .net 2.0 and then upgraded VS many times and latest framework is 3.5 with VS 2015.
On application start I've noticed an exception in Diagnostic Tool which is caught silently
The key 'LocalizedPerfCounter' does not exist in the appSettings configuration section.
Any ideas to fix this problem because this is an application I distribute.
Found an answer on this link and seems it is related to app setting which was missing in app.config file.
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="LocalizedPerfCounter" value="true" />
</appSettings>
</configuration>
I needed to add appSettings section after configSections section.

Dotless HttpHandler with VS2013 Preview

I have just installed the Visual Studio 2013 preview and run up my site. I've noticed that the less files which are used in my site are not being correctly transformed to css and are coming down as blank CSS files.
It appears something is going wrong inside the dotless httphandler as when I force minification for the bundle everything works correctly.
web.config
<section name="dotless" type="dotless.Core.configuration.DotlessConfigurationSectionHandler, dotless.Core" />
...
<httpHandlers>
<add path="*.less" verb="GET" type="dotless.Core.LessCssHttpHandler, dotless.Core" />
</httpHandlers>
...
<handlers>
<add name="dotless" path="*.less" verb="GET" type="dotless.Core.LessCssHttpHandler,dotless.Core" resourceType="File" preCondition="" />
</handlers>
The issue appears to go away if I force minification eg. System.Web.Optimization.BundleTable.EnableOptimizations = false; which suggests something is different in the way it processes the HTTP handler
Try putting handleWebCompression="false" in the configuration for dotless (in the web config)
<dotless minifyCss="false" cache="true" web="false" handleWebCompression="false" />

Sub-folder web.config namespaces remove broken in 4.0?

Similar to this question
I am porting a web application to 4.0. It has a root web.config that adds a namespace:
<namespaces>
<add namespace="Insignia.Catalog2"/>
...
</namespaces>
There is a sub-folder to this app with its own web.config:
<namespaces>
<remove namespace="Insignia.Catalog2"/>
<add namespace="Insignia.Catalog"/>
</namespaces>
.Catalog and .Catalog2 have overlapping class names. This worked great in ASP.NET 2.0 thru 3.5 but seems broken in 4.0 - that is, I now get compiler errors about the colliding class names.
Well I figured it out. While the 'remove' tag WAS removing .Catalog2, another DLL had changed to include a reference to that namespace. Using a control from that other DLL brought .Catalog2 along with it! Fixing the reference solved the problem.