Skip to content

Instantly share code, notes, and snippets.

@vgerbase
vgerbase / web.config
Last active August 6, 2017 14:47
Remove WWW and ensure HTTPS in IIS. Require URL Rewrite module.
<system.webServer>
<rewrite>
<rules>
<rule name="Remove WWW and Ensure HTTPS" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAny">
<add input="{HTTP_HOST}" pattern="^(www\.)" />
<add input="{HTTPS}" pattern="^OFF$" />
</conditions>
<action type="Redirect" url="https://mydomain.com/{R:1}" />
@vgerbase
vgerbase / TableEntityProperties.sql
Created November 9, 2016 23:29
Generate class properties from table
SELECT
'public '
+ CASE
WHEN c.DATA_TYPE IN ('bigint') THEN 'long'
WHEN c.DATA_TYPE IN ('int') THEN 'int'
WHEN c.DATA_TYPE IN ('smallint') THEN 'short'
WHEN c.DATA_TYPE IN ('tinyint') THEN 'byte'
WHEN c.DATA_TYPE IN ('decimal', 'numeric', 'smallmoney', 'money') THEN 'decimal'
WHEN c.DATA_TYPE IN ('real') THEN 'single'
WHEN c.DATA_TYPE IN ('float', 'decimal') THEN 'double'
@vgerbase
vgerbase / DependencyService.cmd
Last active August 6, 2017 14:47
Create a dependency on a Windows service
@Echo Off
Cls
:CheckServiceName
If "%~1"=="" Goto AskServiceName
Set Service=%~1
Goto CheckDependencyServiceName
:AskServiceName
http://dba.stackexchange.com/a/112434
@vgerbase
vgerbase / db_viewdefinition.sql
Created May 13, 2016 21:20
Script to create a role to grant view definition permission in all objects
-- Create a db_viewdefinition role
CREATE ROLE [db_viewdefinition] AUTHORIZATION [dbo];
-- Grant view definition rights to the new role
GRANT VIEW DEFINITION TO [db_viewdefinition];
@vgerbase
vgerbase / db_executor.sql
Last active May 13, 2016 21:19
Script to create a role to grant execute permission in all stored procedures
-- Create a db_executor role
CREATE ROLE [db_executor] AUTHORIZATION [dbo];
-- Grant execute rights to the new role
GRANT EXECUTE TO [db_executor];
@vgerbase
vgerbase / web.config
Last active August 6, 2017 14:49
Elmah Error Filter
<!-- EN-US -->
<errorFilter>
<test>
<or>
<equal binding="HttpStatusCode" value="404" type="Int32" />
<regex binding="Context.Request.ServerVariables['URL']" pattern="/favicon\.ico(\z|\?)" />
</or>
<or>
<and>
@vgerbase
vgerbase / autodiscover.xml
Last active August 28, 2024 16:20
Model for an Autodiscover XML response
<!-- RESPONSE FROM THE SERVER -->
<?xml version="1.0" encoding="utf-8" ?>
<Autodiscover xmlns="http://schemas.microsoft.com/exchange/autodiscover/responseschema/2006">
<!-- Response: Required
This tag serves as an indication that the retrieved XML is an Autodiscovery Response
-->
<Response xmlns="http://schemas.microsoft.com/exchange/autodiscover/outlook/responseschema/2006a">
<!-- User: Optional
This tag gives user-specific information. Autodiscover must be UTF-8 encoded.
-->
@vgerbase
vgerbase / autodiscover.xml
Last active August 28, 2024 16:19
Autodiscover XML request POST
<?xml version="1.0" encoding="utf-8" ?>
<Autodiscover xmlns="http://schemas.microsoft.com/exchange/autodiscover/outlook/requestschema/2006">
<Request>
<AcceptableResponseSchema>http://schemas.microsoft.com/exchange/autodiscover/outlook/responseschema/2006a</AcceptableResponseSchema>
<EMailAddress>[email protected]</EMailAddress>
</Request>
</Autodiscover>
@vgerbase
vgerbase / smtp.cs
Last active August 20, 2022 09:49
C# code to switch off certificate validation
{
...
ServicePointManager.ServerCertificateValidationCallback =
delegate(object s, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) {
return true;
};
smtpclient.Send();
...
}