Configure Memcache with Castle ActiveRecord? - nhibernate

Anyone know how to configure an ActiveRecord/nhibernate application to use Memcache as the 2nd level cache?

Start with the ActiveRecord docs on second level cache configuration. Then, for specific information about Memcached, see this question.
You'll end up with a config similar to this:
<activerecord>
<config>
<add key="connection.driver_class" value="NHibernate.Driver.SqlClientDriver" />
<add key="dialect" value="NHibernate.Dialect.MsSql2005Dialect" />
<add key="connection.provider" value="NHibernate.Connection.DriverConnectionProvider" />
<add key="connection.connection_string" value="Data Source=.;Initial Catalog=test;Integrated Security=SSPI" />
<add key="cache.provider_class" value="NHibernate.Caches.MemCache.MemCacheProvider, NHibernate.Caches.MemCache"/>
<add key="cache.use_second_level_cache" value="true"/>
<add key="cache.use_query_cache" value="true"/>
</config>
</activerecord>

Related

#Html exists, but ActionLink is missing

I have started using VS 2015 from a previous version.
When I loaded the project, I'm missing many helpers such as
#ViewBag
#Html.ActionLink
#Html is recognised by intellisence, but not the ActionLink
In my web.config (in the root) I have
<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" />
</namespaces>
</pages>
Why do I have no ActionLink?
Upgrading to MVC5 resolved the issue as I was previously on MVC4

imageresizer remote reader plugin only displays the remote image if no query strings are present in URL

I'm trying to resize/crop the images stored on one of our servers and use them on another, also our server. Image resizer is running on www.aapg.org. Remote images are stored on assets.aapg.org.
Not sure why it doesn't work. I followed the process outlined in http://imageresizing.net/plugins/remotereader -- everything looks OK. I tried both a signed remote URL and human-friendly syntax, and neither worked for me.
Here are the plugins from the Web.config file I'm using:
<add name="MvcRoutingShim" />
<add name="DiskCache" />
<add name="SeamCarving" />
<add name="SimpleFilters" />
<add name="PdfRenderer" downloadNativeDependencies="true" />
<add name="DropShadow" />
<add name="WhitespaceTrimmer" />
<add name="PrettyGifs" />
<add name="AnimatedGifs" />
<add name="WebPEncoder" />
<add name="WebPDecoder" />
<add name="RemoteReader" />
<add name="CloudFront" />
And the remote reader plugin configuration ('xxxxxxxxxxxxxxxxxxxxxx' is obviously not what I'm using):
<remotereader signingKey="xxxxxxxxxxxxxxxxxxxxxx" allowAllSignedRequests="false" allowRedirects="5">
<allow domain="aapg.org" />
<allow domain="assets.aapg.org" />
</remotereader>
Can anyone tell me what I'm doing wrong? Or what I'm missing?
Thanks in advance!

Could not load type 'PayPal.Manager.SDKConfigHandler' from assembly 'PayPal_Merchant_SDK'

I am trying to integrate paypal mobile checkout into a mobile web app, developed using mvc4, for some reason, when I try to use the function SetMobileExpressCheckout(xxx), I am getting the above error.
I have added the web.config entry across from the sdk example, and have added the reference to the 2 dlls that come with the SDK, but it still crashes, the full error message is below :
{"An error occurred creating the configuration section handler for paypal: Could not load type 'PayPal.Manager.SDKConfigHandler' from assembly 'PayPal_Merchant_SDK'. (C:\Projects\Mobile Development\Print Management\Print Management\web.config line 8)"}
so looking at this, it is pointing to the entry in the web config file, which is added below, I have also created a new project with an empty site, added a page, and all the web.config entries etc, and it works fine.
Could it be something to do with mvc4 ??
I know the web.config entry is large, but I thought I would put it all in there incase it is something else in there causing the problem.
any help would be much appreciated, as I am very close to having this finished, but I just cant seem to find what the issue is here
<?xml version="1.0"?>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=169433
-->
<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"/>
<section name="paypal" type="PayPal.Manager.SDKConfigHandler, PayPal_Merchant_SDK"/>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net"/>
</configSections>
<connectionStrings>
<add name="DefaultConnection" providerName="System.Data.SqlClient" connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=aspnet-Print Management-20130104084836;Integrated Security=SSPI"/>
</connectionStrings>
<paypal>
<settings>
<!-- The URL that the user must be redirected to in order to login and approve some payment actions-->
<add name="paypalUrl" value="https://www.sandbox.paypal.com/webscr"/>
<!-- The API endpoint -->
<add name="endpoint" value="https://api-3t.sandbox.paypal.com/2.0"/>
<!-- Connection timeout in milliseconds -->
<add name="connectionTimeout" value="360000"/>
<!-- The number of times a request must be retried if the API endpoint is unresponsive -->
<add name="requestRetries" value="3"/>
<add name="binding" value="SOAP"/>
<add name="IPAddress" value="127.0.0.1"/>
<!--
API version number. You will not normally have to change this unless you
have a specific need to work with an older version of the API
-->
<add name="APIVersion" value="96.0"/>
</settings>
<accounts>
<!--
Add API credentials - 3 token or client certificate.
You can add multiple account credentials here. The SDK will pick the first account
unless you specifically request an account in the service wrapper mehod.
-->
<account apiUsername="emailaddress" apiPassword="validpassword" apiSignature="signature" applicationId="APP-80W284485P519543T" certificateSubject="" signatureSubject=""/>
<!--
<account apiUsername="enduser_biz_api1.gmail.com" apiPassword="SACH3VA3C29DXGUG"
apiCertificate="<Absolute path to paypal_cert.p12>"
privateKeyPassword="password" applicationId="APP-80W284485P519543T"/>
-->
</accounts>
</paypal>
<!-- Configure logging using the log4net library -->
<log4net>
<appender name="FileAppender" type="log4net.Appender.FileAppender">
<file value="MerchantLog.log"/>
<appendToFile value="true"/>
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date [%thread] %-5level %logger [%property{NDC}] %message%newline"/>
</layout>
</appender>
<root>
<level value="DEBUG"/>
<appender-ref ref="FileAppender"/>
</root>
</log4net>
<appSettings>
<add key="webpages:Version" value="2.0.0.0"/>
<add key="webpages:Enabled" value="false"/>
<add key="PreserveLoginUrl" value="true"/>
<add key="ClientValidationEnabled" value="true"/>
<add key="UnobtrusiveJavaScriptEnabled" value="true"/>
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.0"/>
<authentication mode="Forms">
<forms loginUrl="~/Account/Login" timeout="2880"/>
</authentication>
<pages controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID">
<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"/>
</namespaces>
</pages>
<profile defaultProvider="DefaultProfileProvider">
<providers>
<add name="DefaultProfileProvider" type="System.Web.Providers.DefaultProfileProvider, System.Web.Providers, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="DefaultConnection" applicationName="/"/>
</providers>
</profile>
<membership defaultProvider="DefaultMembershipProvider">
<providers>
<add name="DefaultMembershipProvider" type="System.Web.Providers.DefaultMembershipProvider, System.Web.Providers, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="DefaultConnection" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" applicationName="/"/>
</providers>
</membership>
<roleManager defaultProvider="DefaultRoleProvider">
<providers>
<add name="DefaultRoleProvider" type="System.Web.Providers.DefaultRoleProvider, System.Web.Providers, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="DefaultConnection" applicationName="/"/>
</providers>
</roleManager>
<!--
If you are deploying to a cloud environment that has multiple web server instances,
you should change session state mode from "InProc" to "Custom". In addition,
change the connection string named "DefaultConnection" to connect to an instance
of SQL Server (including SQL Azure and SQL Compact) instead of to SQL Server Express.
-->
<sessionState mode="InProc" customProvider="DefaultSessionProvider">
<providers>
<add name="DefaultSessionProvider" type="System.Web.Providers.DefaultSessionStateProvider, System.Web.Providers, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="DefaultConnection"/>
</providers>
</sessionState>
</system.web>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
<handlers>
<remove name="ExtensionlessUrlHandler-ISAPI-4.0_32bit"/>
<remove name="ExtensionlessUrlHandler-ISAPI-4.0_64bit"/>
<remove name="ExtensionlessUrlHandler-Integrated-4.0"/>
<add name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness32" responseBufferLimit="0"/>
<add name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness64" responseBufferLimit="0"/>
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0"/>
</handlers>
</system.webServer>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35"/>
<bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="2.0.0.0"/>
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35"/>
<bindingRedirect oldVersion="1.0.0.0-4.0.0.0" newVersion="4.0.0.0"/>
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35"/>
<bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="2.0.0.0"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework"/>
</entityFramework>
</configuration>
Had the same issue, and could resolve it by exchanging
PayPal_Merchant_SDK
to
PayPal_Core_SDK
in the configSections part.
The assembly name is wrong in the paypal doc and samples. The config section should reference the assembly name. So "PayPal_Core_SDK" should really be "PayPalCoreSDK"
well, after trying to get it working late into the evening yesterday, I decided to create a new mvc4 mobile web app, and only put in the paypal references etc, and low and behold, it worked, now I am not sure what is wrong with the other app, but I think it will probably be quicker to just transfer my code a cross section by section.
I just thought I would let people know, and if I get chance, I will look at the code again, as I don't like been beat :-)

How to connect my webrole app (vb.net) to my sql azure database?

I am creating a new application (webrole) in webforms called SGS. This application is being build using vb.net.
I am developing the app in windows 7 and have already deployed it to Windows azure.
Every time I need to change something in the application, I change it locally and then publish it again to my production enviroment (i know about staging enviroment in azure, but I prefered the production).
The app is in the start point, now I need to connect it to my database that is in SQL Azure.
I built a new database named SGS that is on SQL Azure and I want to connect my application to it.
I would like that even when I am in the local environment, my application only connects to my sql zure database. This way I don't need any database on my local Pc.
I don't know how to accomplish this.....
The connection string (ado.net) that is on the azure is :
Server=tcp:mwjw08qhju.database.windows.net,1433;Database=SGS;User ID=pr#mwjw08qhju;Password=myPassword;Trusted_Connection=False;Encrypt=True;
My webconfig file as this information:
<xml version="1.0" encoding="utf-8"?>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<system.diagnostics>
<trace>
<listeners>
<add type="Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitorTraceListener, Microsoft.WindowsAzure.Diagnostics, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" name="AzureDiagnostics">
<filter type="" />
</add>
</listeners>
</trace>
</system.diagnostics>
<connectionStrings>
Server=tcp:mwjw08qhju.database.windows.net,1433;Database=SGS;User ID=pr#mwjw08qhju;Password=myPassword;Trusted_Connection=False;Encrypt=True;
<add name="ApplicationServices" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnetdb.mdf;User Instance=true" providerName="System.Data.SqlClient" />
<!-- <add name="DefaultConnection" connectionString="Data Source=.\SQLEXPRESS;Initial
Catalog=aspnet_1db0ca8ec36d4ba1852e5e4ec9947660;Integrated Security=True;MultipleActiveResultSets=True" providerName="System.Data.SqlClient" />-->
<add name="DefaultConnection" connectionString=" <add name="DefaultConnection" connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=aspnet_1db0ca8ec36d4ba1852e5e4ec9947660;Integrated Security=True;MultipleActiveResultSets=True" providerName="System.Data.SqlClient" />
<add name="aspnet_1db0ca8ec36d4ba1852e5e4ec9947660Entities" connectionString="metadata=res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl;provider=System.Data.SqlClient;provider connection string="data source=.\SQLEXPRESS;initial catalog=aspnet_1db0ca8ec36d4ba1852e5e4ec9947660;integrated security=True;multipleactiveresultsets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
</connectionStrings>
<system.web>
<compilation debug="true" strict="false" explicit="true" targetFramework="4.0">
<assemblies>
<add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
</assemblies>
</compilation>
<authentication mode="Forms">
<forms loginUrl="~/Account/Login.aspx" timeout="2880" />
</authentication>
<membership defaultProvider="DefaultMembershipProvider">
<providers>
<clear />
<add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="ApplicationServices" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" applicationName="/" />
<add name="DefaultMembershipProvider" type="System.Web.Providers.DefaultMembershipProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="DefaultConnection" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" applicationName="/" />
</providers>
</membership>
<profile defaultProvider="DefaultProfileProvider">
<providers>
<clear />
<add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="ApplicationServices" applicationName="/" />
<add name="DefaultProfileProvider" type="System.Web.Providers.DefaultProfileProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="DefaultConnection" applicationName="/" />
</providers>
</profile>
<roleManager enabled="false" defaultProvider="DefaultRoleProvider">
<providers>
<clear />
<add name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider" connectionStringName="ApplicationServices" applicationName="/" />
<add name="AspNetWindowsTokenRoleProvider" type="System.Web.Security.WindowsTokenRoleProvider" applicationName="/" />
<add name="DefaultRoleProvider" type="System.Web.Providers.DefaultRoleProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="DefaultConnection" applicationName="/" />
</providers>
</roleManager>
<sessionState mode="InProc" customProvider="DefaultSessionProvider">
<providers>
<add name="DefaultSessionProvider" type="System.Web.Providers.DefaultSessionStateProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="DefaultConnection" applicationName="/" />
</providers>
</sessionState>
</system.web>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" />
</system.webServer>
</configuration>
What do I need to change to accomplish this?
Thank you very much.
This set up should do exactly what you want. It's only slightly more complex if you wanted to connect to SQL Server when running locally BUT SQL Azure when deployed.
To connect to SQL Azure from your local machine though, you'll need to have a firewall rule that allows traffic to reach SQL Azure. Ironically, the post right below yours in Stack Overflow has a response that should help you do this (if you haven't already).
If you set up the firewall rule and are still having issues, post back with more specifics about what's not working, error messages, etc.
Change the Service and Default connection strings to the connection string you received from the Azure SQL portal.
So you will get this:
<add name="ApplicationServices" connectionString="mwjw08qhju.database.windows.net,1433;Database=SGS;User ID=pr#mwjw08qhju;Password=myPassword;Trusted_Connection=False;Encrypt=True;" providerName="System.Data.SqlClient" />
Hope that helps

Load connection strings programmatically

Right now I have to specify connection strings for active record/nhibernate in my config file like so:
<activerecord>
<config type="Navtrak.Business.Schemas.CommonSchemas.Models.NavtrakOperations.NavtrakOperationsDatabase`1, CommonSchemas">
<add key="connection.connection_string" value="connstring1" />
<add key="connection.driver_class" value="NHibernate.Driver.SqlClientDriver" />
<add key="dialect" value="NHibernate.Dialect.MsSql2005Dialect" />
<add key="connection.provider" value="NHibernate.Connection.DriverConnectionProvider" />
<add key="show_sql" value="true" />
<add key="proxyfactory.factory_class" value="NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle" />
</config>
<config type="Navtrak.Business.Schemas.CommonSchemas.Models.Users.UsersDatabase`1, CommonSchemas">
<add key="connection.connection_string" value="connstring2" />
<add key="connection.driver_class" value="NHibernate.Driver.SqlClientDriver" />
<add key="dialect" value="NHibernate.Dialect.MsSql2005Dialect" />
<add key="connection.provider" value="NHibernate.Connection.DriverConnectionProvider" />
<add key="show_sql" value="true" />
<add key="proxyfactory.factory_class" value="NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle" />
</config>
</activerecord>
Then I initialize active record:
if (!ActiveRecordStarter.IsInitialized)
ActiveRecordStarter.Initialize(typeof(SimpleModel).Assembly, ActiveRecordSectionHandler.Instance);
These connection strings must be database-driven so I need a way to programmatically set them. How can I do so? Keep in mind that I connect to multiple databases, in case that makes a difference...
Use InPlaceConfigurationSource. Some examples:
http://www.castleproject.org/activerecord/documentation/trunk/usersguide/configref.html#InPlaceConfigurationSource
http://www.darkside.co.za/archive/2007/09/06/three-ways-to-configure-castle-activerecord.aspx
http://geekswithblogs.net/hammett/articles/76809.aspx
http://code.google.com/p/mausch/source/browse/trunk/LazyTests/FirebirdTests.cs?spec=svn359&r=334#22
http://www.mail-archive.com/castle-project-users#googlegroups.com/msg04503.html