Issue with unwanted connection string appearing in my published web config - webdeploy

I’ve been testing the new web deploy tool with VS 2012 but I have this issue:
I get this extra connection string added to my published web config that I don't currently have in my projects web config.
<add name="name" connectionString="name_ConnectionString" providerName="System.Data.SqlClient" />
Where could this be coming from? It seems like is a relic from past conn strings I've used..
Hope this explains my issue :0)
Thanks for any assistance
Quantum

It has to be coming from one of the web.config files.
Have you checked if a transform to your web.config is applied or not. Check web.release.config, web.debug.config file to check if the connection string is still there.

Related

JSON.NET Production Issue

I have an ASPNET Core project that is running a set of RESTful services using C# and Newtonsoft.JSON 11.0.2 which I incorporated using NuGet. When I run everything locally using Visual Studio 2017 and IIS Express, things work fine and my JSON Deserializer efforts work with no issue.
When I publish the solution in a Web Deploy package and then install that application in IIS 10 on a Windows Server 2016 instance in AWS, the deserializer fails. The error is:
Newtonsoft.Json.JsonReaderException: Unexpected character encountered while parsing value: <. Path '', line 0, position 0
It does not matter if I publish in Debug or Release mode.
I ran Postman calls and the JSON being returned is both validate and produces the correct objects. I did see that, in the Solution Explorer, the version is 11.0.2 but in the assets JSON file, the version is pointed to 10.0.1. The .CS project file, when viewed in a text editor outside of Visual Studio, does show 11.0.2.
When I look in the deployed application's folder on the server, I do not see any NewtonSoft DLLs but I do see other NuGet-obtained DLLs. This might not be an issue given how JSON.NET deploys but I thought it was worth mentioning.
I then included a logger and sent the incoming JSON to a file and, again, it all validated as expected.
I have tried everything, ensured CORS is properly implemented both in the application and in IIS. I am at a complete loss as to how to proceed.
Can somebody please help?
Thank you!
I had the same problem and solved by this code in web.config
<system.webServer>
<handlers>
<remove name="WebDAV" />
<remove name="ExtensionlessUrlHandler-Integrated-4.0" />
<remove name="OPTIONSVerbHandler" />
<remove name="TRACEVerbHandler" />
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
</handlers>
<modules>
<remove name="WebDAVModule" />
</modules>
</system.webServer>
I sometimes browse old question that has no/accepted answers and check if they are still in need of some help, or if something can be done to close the cold case.
This post has already been solved, but the cause and the solution were left only in the comments.
If the first character encountered when parsing is <, you can be sure
that is not JSON. Something is probably sending XML or HTML to your
code in the deployed environment. I would look at that angle. This
doesn't seem like a version conflict to me, otherwise you would be
getting a much different error about not being able to load the file
or assembly. I think this is solely a data problem.
Brian Rogers
#Brian Rogers - Thank you SO MUCH for this last comment. I ended up
opening Production to my development machine and then running
Wireshark to see the communications. Turns out that IIS had "GEWT"
instead of "GET" in the allowed methods web.config for the host
website and I was getting rejections in the cloud instead of the JSON.
Every test I ran which generated output was LocalHost but, of course,
none of the real production work used anything local. Once I fixed
that error, everything worked great!
Ken Tola
#ken-tola, can you please self-answer the question and then accept it to close the case.

RavenDB 2 returns 401 when trying to create database

This is a fresh install of Raven #2230, running on IIS8/Win8. When studio starts it offers to create new database, then browser pops up credentials window (401).
Web.config has add key="Raven/AnonymousAccess" value="All"/ set. Also tried add key="Raven/AnonymousUserAccessMode" value="All"/ as per documentation.
Anonymous Authentication on site is enabled, so is Windows Authentication.
Added Raven.Bundles.Authorization.dll to plugins folder (not sure if needed, but didn't make any difference).
Am I missing something ?
RavenDB as of today, is on version 2750 (stable). Upgrade and this issue should be fixed.
The way to do this is to set the AnonymousAccess setting in web.config to Admin:
<add key="Raven/AnonymousAccess" value="Admin"/>
You should change this back to All once you have created your database.

Connecting to an existing database in a ASP.NET MVC4 Web API project

I'm building an web api using ASP.NET web api framework. I have seen a few tutorials on how to get started but I haven't found to use an existing SQL Server database. I have the database up and running also added the data connection to the database explorer in VS but I don't know how to connect the database to my project so I can start using it as my repository. How can I do that?
Put the following in your application web.config file and replace "yourConnectionString" with the actual connection string.
<configuration>
<connectionStrings>
<add name="DbConnection" connectionString="yourConnectionString" />
</connectionStrings>
</configuration>
In the code use System.Configuration.ConfigurationManager.ConnectionStrings["DbConnection"].ConnectionString to get its value. You might need to reference the "System.Configuration" assembly in your project.

LocalSqlServer was not found in the applications configuration or the connection string is empty

I've just upgraded a .NET 3.5 MVC 1 project to .NET 4.0 MVC 3 and for some reason now when I try to run it it says:
The connection name 'LocalSqlServer' was not found in the applications
configuration or the connection string is empty.`
I'm not sure why it does this as no where in my code does it look for a LocalSqlServer connection string, and if I put in a LocalSqlServer connection string in my config file with the value of my standard connection string and try to go onto the website, it takes me to the 'please log in' URL but with a 404 page (and not the custom 404 page either)
Anyone know what the problem could be?
Regards,
Harry
The LocalSqlServer connection string is defined in your Machine.config.
If you don't have a default Machine.config file, it might have been removed. You would then need to re-add it inside your own Web.config.
My LocalSqlServer:
<add name="LocalSqlServer" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true" providerName="System.Data.SqlClient"/>
You can find your machine.config here:
C:\Windows\Microsoft.NET\Framework\[FRAMEWORK VERSION]\CONFIG\machine.config
I have been tracking this same issue on a local application. When I had started working on it, the application was running ASP.NET Framework version 4.5. In the past, it had implemented structures from namespace System.Web.Providers. We updated the code to no longer use these classes and removed their references in the Web.config but we still received this error.
What I determined was the System.Web.Providers.dll was still present within the bin directory. We removed the reference before we performed a Clean or Rebuild, so the Clean or Rebuild action never removed it. (Note: It also never cleaned other files from references we removed before the Clean/Rebuild.) After deleting the files from the corresponding application bin directory, the application no longer threw the exception related to LocalSqlServer.

Disable proxy for entire application?

Ever since upgrading to Visual Studio 2010, I'm running into an issue where the first web request of any type (WebRequest, WebClient, etc.) hangs for about 20 seconds before completing. Subsequent calls work quickly. I've narrowed down the problem to a proxy issue.
If I manually disable proxy settings, I don't experience this delay:
Dim wrq As WebRequest = WebRequest.Create(Url)
wrq.Proxy = Nothing
What's strange is that there are no proxy settings enabled on this machine in Internet Options. What I'm wondering is if there is a way to disable proxy settings for my entire project in one shot without explicitly disabling as above for every web object.
The main reason I want to be able to do this is that I'm trying to use an API (http://code.google.com/p/google-api-for-dotnet/) which uses web requests, but does not provide any way to manually disable proxy settings.
I have found some information suggesting that I need to add some proxy information to the app.config file, but I get errors building my program if I make an edits to that file.
Can anyone point me in the right direction?
Brent - that's the correct solution : adding a defaultProxy element to your application's configuration file.
So for a website, it's the web.config. For an .exe application, it's .config.
And those settings are also correct :-
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.net>
<defaultProxy enabled="false" useDefaultCredentials="false">
<proxy/>
<bypasslist/>
<module/>
</defaultProxy>
</system.net>
</configuration>
Instead of turning off the proxy setting altogether you can try using the bypasslist to turn it off for the servers that you're having problems with.
See http://msdn.microsoft.com/en-us/library/kd3cf2ex.aspx for details and a sample.
If you're having problems changing the app.config I suggest posting the errors and possibly the app.config as well.