I had done one publish to my MVC application. After that, I cannot debug it anymore!
This is the error. It seems that my visual studio web server is loading machine.config
Server Error in '/' Application.
Configuration Error
Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately.
Parser Error Message: The connection name 'LocalSqlServer' was not found in the applications configuration or the connection string is empty.
Source Error:
Line 255:
Line 256:
Source File: C:\Windows\Microsoft.NET\Framework\v4.0.30319\Config\machine.config Line: 257
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.237
This is how my web.config looks like, and there is nothing in my code that uses ASP.Net Membership as my authentication mode is "Windows".
I did manage to run it again in Visual Studio once, after I set the build mode from "Release" to "Debug" vice versa, but after I published again today.. The problem came back.
<configuration>
<connectionStrings>
<clear/>
<add name="ApplicationServices" connectionString="Data Source=SCG1SQL-64;Initial Catalog=Metallurgy;Integrated Security=True"
providerName="System.Data.SqlClient" />
<add name="mandb100ConnectionString" connectionString="Data Source=scg1sql-64;Initial Catalog=mandb100;Integrated Security=True"
providerName="System.Data.SqlClient" />
</connectionStrings>
<appSettings>
<add key="webpages:Version" value="1.0.0.0" />
<add key="ClientValidationEnabled" value="true" />
<add key="UnobtrusiveJavaScriptEnabled" value="true" />
</appSettings>
<system.web>
<authentication mode="Windows"/>
<authorization>
<deny users="?" />
</authorization>
</system.web>
</configuration>
Well, it is using the machine.config. There is a hierarchy of configuration. In other words, if you don't explicitly specify (or remove or clear) in your web.config, the base defaults will be pulled from the machine.config.
What your ASP.NET application will do is look for a web.config in the current directory for configuration. If that isn't found, or the desired configuration isn't found, it'll look to the application's web.config. Then for defaults, or uncleared or nonremoved items it'll also pull configuration from the machine.config.
But to the problem. What your error message is saying is that it can't find the LocalSqlServer connection string name anywhere. Are you sure that conn string name exists in your web.config?
Edit: Check your web.release.config file. You can find it in your Solution Explorer if you drop down the web.config file. Does that perhaps contain LocalSqlServer connection string?
This link might be of help: http://msdn.microsoft.com/en-us/library/webmatrix.webdata.preapplicationstartcode(v=vs.99).aspx
That's how I solved my problem. Apparently, this WebMatrix SimpleMembership is enabled by default. So I added this line in my web.config, and the problem disappeared!!!
<add key="enableSimpleMembership" value="false"/>
I know this is an old post, and as both these answers are correct to point you in the right direction to solve the issue, I'd like to add another solution if it might help anyone.
In my application an error occurred after I used the "Add Deployable Dependencies..." item in Solution Explorer, project context menu (right click on a project). This added a directory called _bin_deployableAssemblies with dlls needed to deploy your application on a server if it doesn't have some of them added to GAC. The dlls in the _bin_deployableAssemblies are copied to the bin directory of your application.
There were two dlls of interest that I wasn't using WebMatrix.Data and WebMatrix.WebData. Their presence in the bin directory of my application somehow messes the default membership provider resolving (correct me if I'm wrong, or add an explanation to what really happens :) ). The solution was to simply remove the offending dlls from the bin directory and from the _bin_deployableAssemblies as well.
Related
We currently use .Net Framework 4.8 but are upgrading Windows console apps to .Net 6.0. In 4.8, we would use Microsoft.Configuration.ConfigurationBuilders.UserSecrets to help manage keys in our app.config that we wanted to keep secret(production level keys mainly).
Our app.config would look like the following:
<configSections>
<section name="configBuilders" type="System.Configuration.ConfigurationBuildersSection, System.Configuration, Version=4.0.0.0, Culture=neutral, PublicKeyToken=xxxxxxxxxx" restartOnExternalChanges="false" requirePermission="false" />
</configSections>
<configBuilders>
<builders>
<add name="Secrets" userSecretsId="production" type="Microsoft.Configuration.ConfigurationBuilders.UserSecretsConfigBuilder, Microsoft.Configuration.ConfigurationBuilders.UserSecrets, Version=1.0.0.0, Culture=neutral" />
</builders>
</configBuilders>
<appSettings configBuilders="Secrets">
<add key="Sample" value="SECRET"
</appSettings>
Our Production secrets.xml:
<root>
<secrets ver="1.0">
<secret name="Sample" value="production" />
</secrets>
</root>
Anytime we would reference the key Sample, it would look at the key in app.config notice that the value was SECRET. Then it would go to AppData\Microsoft\UserSecrets\{userSecretId}\secrets.xml to replace SECRET with the value in secrets.xml
Is there a similar way to do this in .Net 6.0? I know the config files are changing to JSON but I would like to support this pattern while I upgrade. I also know that Microsoft.Configuration.ConfigurationBuilders.UserSecrets hasn't been released in a couple of years.
I appreciate any help.
I have a .NET MVC application that uses Azure Active Directory for Auth.
I'm trying to add a custom JWTSecurityTokenHandler to authenticate a console app that performs some basic GET requests against the app. However every request just gets redirected to the Azure AD login page instead of being passed to the JWT handler (my breakpoints and logging statements in the handler are not being hit). Any ideas?
Web.config:
<system.identityModel>
<identityConfiguration>
<audienceUris>
<add value="https://localhost:44300/" />
</audienceUris>
<securityTokenHandlers>
<add type="QS.Admin.Infrastructure.MyJwtHandler, QS.Admin" />
<securityTokenHandlerConfiguration>
<certificateValidation certificateValidationMode="None" />
</securityTokenHandlerConfiguration>
</securityTokenHandlers>
<issuerNameRegistry type="System.IdentityModel.Tokens.ValidatingIssuerNameRegistry, System.IdentityModel.Tokens.ValidatingIssuerNameRegistry">
<authority name="https://[myaccessdomain].accesscontrol.windows.net/">
<keys>
<add thumbprint="[thumbprint]" />
</keys>
<validIssuers>
<add name="https://[myaccessdomain].accesscontrol.windows.net/" />
</validIssuers>
</authority>
</issuerNameRegistry>
<!--certificationValidationMode set to "None" by the the Identity and Access Tool for Visual Studio. For development purposes.-->
<certificateValidation certificateValidationMode="None" />
</identityConfiguration>
</system.identityModel>
<system.identityModel.services>
<federationConfiguration>
<cookieHandler requireSsl="false" />
<wsFederation passiveRedirectEnabled="true" issuer="https://[myaccessdomain].accesscontrol.windows.net/v2/wsfederation" realm="https://localhost:44300/" requireHttps="false" />
</federationConfiguration>
</system.identityModel.services>
in addition to the above advice,
the jwtsecuritytokenhandlers responsibility is to validate a jwt and serve claims upstream. I don't see session management anywhere in your config, if that is missing, each call to the host will require obtaining a new token from ACS.
The settings in web.config look right.
Couple of things to check :
Make sure ACS is configured to issue JWT tokens for your realm.
If you plug in the JwtSecurityTokenHandler from MS - is it getting hit? This will help in isolating the issue to your custom handler versus settings in ACS or web.config.
I'm following this tutorial : http://msdn.microsoft.com/en-us/data/jj193542 for Code First basics using ADO.NET EF. The problem is that when executing the code the DataBase is not created automatically and I think that this is because the configurations in my app.config but it's my first day with real code and I can't figure out how to adjust my config file so I can connect to my server and use a created DataBase if neccessary or let the program from the tutorial create new database as expected from what is written.
This is my App.config file:
<?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>
<entityFramework>
<!-- <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
<parameters>
<parameter value="v11.0" />
</parameters>
</defaultConnectionFactory> -->
<connectionStrings>
<add name="BloggingContext"
providerName="System.Data.SqlClient"
connectionString="server=milka-pc\sqlserver2012;Database=Panorama;user id=MyID;password=MyPass;port=3333;Integrated Security=True;"/>
</connectionStrings>
<!--<contexts>
<context type=" Blogging.BloggingContext, MyAssembly">
<databaseInitializer type="Blogging.MyCustomBlogInitializer, MyAssembly" />
</context>
</contexts>-->
</entityFramework>
</configuration>
As you can see some parts are commented as I tried a various things to make it work.
This is how y server explorer looks like while I'm trying to connect:
Also since I have zero experience with ViasualStudioXXXX and connecting to DataBases this is what I see and how I select my server:
There in milka-pc\sqlserver2012 I have a DB named Panorama which I can use or better follow the tutorial step by step and leave the program to create my new DB. For now I can't neither of these two. And to connect to milka-pc\sqlserver2012 I need to provied UserName and Password which I did in App.config. I say this just to know that these fields are not blank
If you are sure that milka-pc\sqlserver2012 is in fact working on port 3333 as you suggested
change your connectionstring to this:
<add name="BloggingContext"
providerName="System.Data.SqlClient"
connectionString="server=milka-pc\sqlserver2012,3333;Database=Panorama;user id=MyID;password=MyPass;Integrated Security=True;"/>
Just to make sure try that connection string in you SQL management studio with provided credentials.
If that doesnt work consult your sql server configuration manager, specifically under SQL server Network configuration make sure that your instance has enabled TCP/IP pipe with appropriate port enabled.
Cheers.
I'm a real newbie in MVC3 but excited to learn. Guide me how to change connection from App_Data (DB.mdf) to MS SQL Server 2008.
MDF connection
<add name="MvcMusicStoreEntities" connectionString="metadata=res://*/Models.MusicStore.csdl|res://*/Models.MusicStore.ssdl|res://*/Models.MusicStore.msl;provider=System.Data.SqlClient;provider connection string="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\MvcMusicStore.mdf;Integrated Security=True;User Instance=True;MultipleActiveResultSets=True"" providerName="System.Data.EntityClient" />
This is a working one from my running project:
<add name="CONNECTION_NAME" connectionString="data source=SQL_SERVER_IP\INSTANCE_NAME; User ID=SQL_USER_NAME; Password=YOUR_PASSWORDd;Initial catalog=DB_NAME" providerName="System.Data.SqlClient" />
for your posted one, it may look like this:
as I can see, you are not following the MVC3 version of music store, or that's how it look for me as I've checked the PDF file of the MVC3 vesion and found that Jon Galloway is using the connecion string just like the one I'm using.
check out the PDF from here: http://mvcmusicstore.codeplex.com/releases/view/59112#DownloadId=197609
That's it, no other parts are required.
this is also a very very nice resource for you to find the different ways that you can do to configure your app connection string.
http://www.connectionstrings.com/sql-server-2008
From SQL Server 2008 connection strings
Data Source=myServerAddress;
Initial Catalog=myDataBase;
User Id=myUsername;
Password=myPassword;
Example:
<add name="NAME" connectionString="Data Source=.\SQLExpress; User ID=username; Password=password;Initial catalog=database" providerName="System.Data.SqlClient" />
If you are going to use Entity Framework you need to change the provider to
providerName="System.Data.EntityClient"
And modify the add tag:
<add name="Entities" connectionString="metadata=res://*/;provider=System.Data.SqlClient;provider connection string="Data Source=.\SQLExpress;Initial Catalog=Test;Persist Security Info=True;User ID=test;Password=test;MultipleActiveResultSets=True"" providerName="System.Data.EntityClient"/>
I'm new to ASP.NET MVC and don't understand the purpose of all the JavaScript files that are added to the project by default.
What's the purpose of MicrosoftMvcValidation.js? Whatever it's used for, can it be swapped out for a jquery-based implementation? If so, how?
MicrosoftMvcValidation.js will be used if you decide that you do not want to use the new unobtrusive jQuery validation on the client side.
You can make this choice for you entire applicastion in the web.config file here:
<appSettings>
<add key="ClientValidationEnabled" value="true"/>
<add key="UnobtrusiveJavaScriptEnabled" value="true"/>
</appSettings>
So in the above example the jQuery validation will be used.