SubSonic deployment and changing connectionstrings - subsonic

I used Subsonic to build the DAL for one of my web applications. When I move it from my test server to the production server I change the connectionstring to point to the production datasource but the app still runs against the test DB. Is the connection information stored someplace else in addition to the Web.config?
What are the best practices for deploying web apps built using Subsonic?
TIA
John

In your SubSonicService configuration section, does the connectionStringName attribute point to the correct connection string?

Here is an example of my config.
<!--########################## Connection Strings ###############################-->
<connectionStrings>
<clear/>
<add name="Ajax"
connectionString="Data Source=Ajax1;Initial Catalog=AjaxExample_test;User ID=Webuser;Password=Pinecone!"
providerName="System.Data.SqlClient"/>
</connectionStrings>
<!--########################## SubSonic ###############################-->
<SubSonicService defaultProvider="AjaxProv">
<providers>
<clear/>
<add name="AjaxProv" type="SubSonic.SqlDataProvider, SubSonic"
connectionStringName="Ajax"
generatedNamespace="ICBA.Web.SalesForce.StagingDAL"
appendWith=""
stripColumnText=""
relatedTableLoadPrefix=""
enableTrace="false"
extractClassNameFromSPName="false"
fixDatabaseObjectCasing="true"
fixPluralClassNames="true"
generateLazyLoads="false"
generateNullableProperties="true"
generateODSControllers="true"
generateRelatedTablesAsProperties="false"
includeProcedureList="*"
excludeTableList=""
includeTableList="*"
regexDictionaryReplace="TypeCode,typecode"
regexIgnoreCase="true"
removeUnderscores="true"
setPropertyDefaultsFromDatabase="false"
useExtendedProperties="false"
useSPs="true"/>
</providers>
</SubSonicService>

Related

application Initialization webapi always requesting default.aspx

I've been trying to configure IIS to request a custom URL to warm up my webapi.
My config is like this.
<applicationInitialization doAppInitAfterRestart="true" skipManagedModules="false">
<add initializationPage="/api/transaction/5" />
</applicationInitialization>
This is working but IIS also calls the root web app (/default.aspx) to warm up as well. And I'm wondering how to remove this call as I don't need it.
Thanks for you help!
Patrick
Looks like this config section is working with collection of initialization elements. Try to clear this collection before adding your page:
<applicationInitialization doAppInitAfterRestart="true" skipManagedModules="false">
<clear/>
<add initializationPage="/api/transaction/5" />
</applicationInitialization>

How to define connection string for session state in Azure

I am using the RedisSessionStateProvider using a procedimient like this https://azure.microsoft.com/en-us/documentation/articles/web-sites-dotnet-session-state-caching/
I define its connection string in web.config, in this example is XXXXXX.
<system.web>
<compilation debug="true" targetFramework="4.6.1" />
<httpRuntime targetFramework="4.5" />
<globalization culture="es-CO" uiCulture="es" />
<customErrors mode="Off" />
<sessionState mode="Custom" customProvider="SessionStateStore">
<providers>
<add name="SessionStateStore" type="Microsoft.Web.Redis.RedisSessionStateProvider" connectionString="XXXXXX" throwOnError="true" applicationName="NominappSession" />
</providers>
</sessionState>
</system.web>
I dont want to put the connection string in the source code. So how can i using the settings in Azure to define this connection string?
I deploy to azure from github, so it uses Kudu. I dont have an external CI server.
Any advice please?
I did it :)
To do that you need to define the connection string as a environment variable, not as a typical connection string. And in the sesion state provide use the environment variable name.
This way:
<appSettings>
<add key="REDIS_CONNECTION_STRING" value="redis,allowAdmin=true" />
</appSettings>
<system.web>
<sessionState mode="Custom" customProvider="SessionStateStore">
<providers>
<add name="SessionStateStore" type="Microsoft.Web.Redis.RedisSessionStateProvider" connectionString="REDIS_CONNECTION_STRING" applicationName="REDIS_SESSION_APPLICATION_NAME" throwOnError="true" />
</providers>
</sessionState>
</system.web>
Using that you can now define the connection string in the App Settings of Azure WebSites
If you just want to be able to provide your connection string from your source code, you can use the settingsClassName and settingsMethodName properties in the config, like so:
<sessionState mode="Custom" customProvider="RedisSessionStateStore">
<providers>
<add
name="RedisSessionStateStore"
type="Microsoft.Web.Redis.RedisSessionStateProvider"
settingsClassName="MyApp.SessionStateRedisSettings,MyApp"
settingsMethodName="ConnectionString" />
</providers>
In here, the settingsClassName is the name of a class in your app, with its fully qualified namespace. The settingsMethod name is the name of the method on this class, which must be static, take 0 parameters and return an string. For example:
namespace MyApp
{
public static class SessionStateRedisSettings
{
public static string ConnectionString()
{
return "ConnectionString goes here";
}
}
}
From here: https://github.com/Azure/aspnet-redis-providers/wiki/Configuration
Take a look at Scott Hanselman's blog on the subject:
http://www.hanselman.com/blog/HowToKeepYourASPNETDatabaseConnectionStringsSecureWhenDeployingToAzureFromSource.aspx
You can store the connection string inside of the app settings within the azure portal and then call them from within your app. This prevents the string from being contained within your source code. You'll want to do the same with your storage keys as well.
In the portal go to the settings of your app, and select "Application Settings". Scroll down on that pane to Connection Strings.
Check out the connection strings section of this page as well:
https://azure.microsoft.com/en-us/documentation/articles/web-sites-configure/
I think IPartitionResolver can come to rescue here...
You can basically create a class that implements System.Web.IPartitionResolver interface and specify it in the sessin state configuration in web.config as this
<sessionState mode="Custom" partitionResolverType="WebAppConnectionStringResolver">
And then in the class you can override the connection string
public class WebAppConnectionStringResolver : System.Web.IPartitionResolver
{
public void Initialize()
{
}
public string ResolvePartition(object key)
{
return System.Configuration.ConfigurationManager.ConnectionStrings["your_Conn_string_name_in_portal"]
}
}
I havent tested this out but I believe this should work
Read more at
https://msdn.microsoft.com/en-us/library/system.web.configuration.sessionstatesection.partitionresolvertype(v=vs.110).aspx
https://msdn.microsoft.com/en-us/library/system.web.ipartitionresolver(v=vs.110).aspx

Why is CloudConfigurationManager using my Cloud.cscfg instead of Local.cscfg too?

I do realise that his question was asked and answered, but unfortunately the solution of complete clean, rebuild, restart.. doesn't work in my case and my lowly reputation doesn't allow me to comment. So I am I think compelled to ask it again with my info.
Sample code:
CloudStorageAccount storageAccount;
string settings = CloudConfigurationManager.GetSetting("StorageConnectionString");
storageAccount = CloudStorageAccount.Parse(settings);
I have my web.config section like this:
<appSettings>
<add key="owin:AppStartup" value="zzzz" />
<add key="webpages:Version" value="3.0.0.0" />
<add key="webpages:Enabled" value="false" />
<add key="ClientValidationEnabled" value="true" />
<add key="UnobtrusiveJavaScriptEnabled" value="true" />
<add key="StorageConnectionString" value="DefaultEndpointsProtocol=https;AccountName=xxxx;AccountKey=yyyy"/>
</appSettings>
In the ServiceConfiguration.Cloud.cscfg I have:
<ConfigurationSettings>
<Setting name="Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString" value="DefaultEndpointsProtocol=https;AccountName=nnnn" />
<Setting name="StorageConnectionString" value="DefaultEndpointsProtocol=https;AccountName=xxxx;AccountKey=yyyy"/>
</ConfigurationSettings>
and in the ServiceConfiguration.Local.cscfg I have:
<ConfigurationSettings>
<Setting name="Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString" value="UseDevelopmentStorage=true" />
<Setting name="StorageConnectionString" value="UseDevelopmentStorage=true" />
</ConfigurationSettings>
I converted this to an Azure project from a standard MVC web project in order to use the Azure storage blobs etc. I am finding that no matter what I seem to do it always uses the Azure storage.
As I step through the code snippet above.. I can clearly see the returned connection string as the one coming from the web.config app setting... I feel I must be doing something fundamentally wrong or missing something..?
A small point (maybe?) as I converted the project over, there was an error message (on a pop up and not saveable) about a connection string error and it not working. I hadn't even created this particular connection string at that time and the only other one (for localDB does work). That however is in the web.config section and as it ain't broke I didn't fix it to go into the ..
Any help would be appreciated.
Further Addition, from the comments by Igorek below, I did check the Role settings and they appear to be correct.
Then .. after a lot of messing around, some experiments which still didn't work, I've taken a step back. I actually don't want a cloud service, I ended up with one because I thought I needed one to access Blobs and Queues, I had already decided that WebJobs seems like the way to go first to keep as abstracted as possible.
So I have rolled back to prior to the Web SITE that I had before and found but I still CAN'T seem to get it to use development storage.. although I imagine that CLoudConfigurationManager probably doesn't handle Web Sites? Any tips?
Check into settings of your Role within the cloud project. It will have a default for which configuration it starts with. Simply swap from Cloud to Local.

Cannot use SQL server (LocalDB) after moving from IIS Express to Local IIS

When I run my website under local IIS instead of embedded IIS express I got the following error when accessing database (mdf file at app_data)
A network-related or instance-specific error occurred while
establishing a connection to SQL Server. The server was not found or
was not accessible. Verify that the instance name is correct and that
SQL Server is configured to allow remote connections. (provider: SQL
Network Interfaces, error: 26 - Error Locating Server/Instance
Specified)
Here the connection string:
Data Source=(LocalDB)\v11.0;AttachDbFilename=C:\Sources\Local\WebApplication1\WebApplication1\App_Data\aspnet-WebApplication1-20140226022052.mdf;Integrated Security=True
From Visual Studio and IIS Express I could connect to that database:
https://db.tt/rBXiwyA5
But the issue is that I need to have access to deployed application from another computer and IIS Express doesn't allow remote connections. That is why I was forced to use Local IIS.
Thank you for any advises!
you may need to double escape the \
"Data Source=(LocalDB)\v11.0;Integrated Security=true"
Unable to connect to localDB in VS2012 – "A network-related or instance-specific error occurred while establishing a connection to SQL Server..."
If you are using EntityFramework, try put it on App.config, worked for me.
<?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=6.0.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>
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
</entityFramework>
</configuration>
There are couple of things to try:
Provide the connection string in the format of, e.g.
Data Source=(LocalDb)\MSSQLLocalDB;Initial Catalog=aspnet-WebApplication;Integrated Security=SSPI
On IIS, right click on the related App Pool then go to Advanced Settings, then set "Load User Profile" to true.
In my experience this did not change anything, so I had to do this manually in the applicationHost.config file found in C:\Windows\System32\inetsrv\config. Specifically, make sure "loadUserProfile" and "setProfileEnvironment" properties are set to true:
<applicationPools>
..
<add name="MyAppPool" autoStart="true" managedRuntimeVersion="v4.0" managedPipelineMode="Integrated">
<processModel identityType="ApplicationPoolIdentity" loadUserProfile="true" setProfileEnvironment="true" />
</add>
..
<applicationPools>
Alternatively you could try changing Identity under App Pool
Advanced Settings from ApplicationPoolIdentity to
LocalSystem.
After doing one of these things you will hopefully stop getting this error, yet you may find that the application behaves as if there is no data in the database. This is because unlike SQLExpress or SQL Server, LocalDB runs as a user-specific process. Hence you might need to seed the database for the current database user (depending on the Application Pool/Identity being used) .
these links might provide an answer:
http://blogs.msdn.com/b/sqlexpress/archive/2011/12/09/using-localdb-with-full-iis-part-1-user-profile.aspx
http://blogs.msdn.com/b/sqlexpress/archive/2011/12/09/using-localdb-with-full-iis-part-2-instance-ownership.aspx

PUT + DELETE Http Verbs returning 401/405 from API on shared hosting webserver

I have created an MVC Web Api for some university coursework, that works as expected on my development machine (Running VS11).
However when I deploy the application to the webserver on 123reg HttpVerbs other than GET and POST appear to not reach my application at all, initially a 401 Not Authorised response was returned; however after turning off the "WebDAV" module as suggested here these 401s became 405 Method not allowed. In this case I only disabled the handlers as disabling both the handlers and the module meant that my application did not start at all (Error 500 without a stacktrace [custom errors are off]).
I am planning to utilise the forms membership provider to add authentication capabilities to my API, however I removed any [Authorise] attributes from my code when 401s began appearing.
Applications on 123Reg's shared hosting are run under Medium trust.
I have been in contact with 123Reg support, and they have been semi helpful, but have since decided that they cannot help me further (They suggested adding HttpHandlers as detailed below) (Apparently, I should consult a web designer...)
Things I have tried:
I have added [AllowAnonymous] Attributes to my controllers and/or actions with no effect.
I have added the authorization web.config attribute allowing all verbs and paths to all users both authenticated and not:
<authorization>
<allow users="*" />
<allow users="?" />
<allow verbs="*" users="*" />
<allow verbs="*" users="?" />
</authorization>
I have added (As suggested by 123Reg):
<system.webServer>
<handlers>
<remove name="WebDAV" />
<add name="PUTVerbHandler" path="*" verb="PUT" modules="ProtocolSupportModule" resourceType="Unspecified" />
<add name="DELETEVerbHandler" path="*" verb="DELETE" modules="ProtocolSupportModule" resourceType="Unspecified" />
</handlers>
</system.webServer>
This appeared to be a step forward, as we now receive 405 responses rather then 401 respones, however I am now unable to make any further progress. Additionally I have also added:
<httpHandlers>
<add verb="*" path="*" type="System.Web.Mvc.MvcHttpHandler"/>
</httpHandlers>
This also made no difference.
Any help you can give would be much appreciated (I dont really want to have to move host for this application!)
This post solved my problem. I did all the regular things: added all the necessary <handlers> entries, disabled WebDAV, but I still had 401.3 Unauthorized.
Enabling forms authentication solved the problem:
<system.web>
<compilation debug="true" targetFramework="4.0" />
<authentication mode="Forms" />
</system.web>
I found this: http://forums.iis.net/t/1163441.aspx
From the looks of that forum post, you need to completely uninstall WebDAV for the PUT and DELETE Verbs to work. This is not going to help on a shared webhosting scenario unfortunately.
For me it was something different.
I had to go to the site folder, open the security tab for the folder, press Edit button to change group or user names permissions, find the site from my IIS 8 sites and give it a full control permission.

Resources