Skip to content

Instantly share code, notes, and snippets.

View odenijs's full-sized avatar
🏠

Okke de Nijs odenijs

🏠
View GitHub Profile
@model UmbracoLogin.MemberLoginModel
@if (User.Identity.IsAuthenticated)
{
<p>Logged in: @User.Identity.Name</p>
<p>@Html.ActionLink("Log out", "MemberLogout", "MemberLoginSurface")</p>
}
else
{
using (Html.BeginUmbracoForm("MemberLogin", "MemberLoginSurface"))
{
@odenijs
odenijs / jQuery - add wmode to iframe source
Created June 26, 2013 12:38
Add wmode query variable to iframe source with jQuery
$('iframe').each(function() {
var source = $(this).attr('src');
var wmode = "wmode=opaque";
if (source.indexOf('?') != -1) {
$(this).attr('src', source + '&' + wmode);
} else {
$(this).attr('src', source + '?' + wmode);
}
});
@odenijs
odenijs / 404 redirect global asax
Created June 27, 2013 11:50
Global asax 404 redirect on application error to skip 302 status first. http://stackoverflow.com/questions/667053/best-way-to-implement-a-404-in-asp-net
protected void Application_Error(object sender, EventArgs e)
{
//Application.Lock();
//Application["LastException"] = Server.GetLastError();
var serverError = Server.GetLastError() as HttpException;
if (serverError != null)
{
int errorCode = serverError.GetHttpCode();
@odenijs
odenijs / boilerplate httphandler
Created July 3, 2013 08:03
A boilerplate template to use for an HttpHandler <httpHandlers> <add verb="GET,POST,WHATEVER" path="SomeEndPoint.ashx" type="MyNamespace.MtHandler, MyAssemblyName" /> </httpHandlers>
public class MyHandler : IHttpHandler
{
private const string CONSTSOMEPARAM = "SomeParam";
public MyHandler(){}
public void ProcessRequest(HttpContext context)
{
// Don't allow this response to be cached by the browser.
// Note, you MIGHT want to allow it to be cached, depending on what you're doing.
@odenijs
odenijs / httphandler
Created July 4, 2013 15:57
Boilerplate httphandler abstract class
// <summary>
/// An abstract base Http Handler for all your
/// <see cref="IHttpHandler"/> needs.
/// </summary>
/// <remarks>
/// <p>
/// For the most part, classes that inherit from this
/// class do not need to override <see cref="ProcessRequest"/>.
/// Instead implement the abstract methods and
/// properties and put the main business logic
@odenijs
odenijs / Alt text from image name
Created July 31, 2013 13:22
Get the alt text from an image path from it's title with the extension
public static string GetAltTextFromImage(string path)
{
string result = string.Empty;
if (!string.IsNullOrEmpty(path))
{
// Get start position for image name from path
int first = path.LastIndexOf("/") + 1;
// Get last position for image name from path
@odenijs
odenijs / Replace domein in all links
Created July 31, 2013 13:23
Replace domain in all href attributes
/* IE 6 */
* html .yourclass { }
/* IE 7 */
*+html .yourclass{ }
/* IE 7 and modern browsers */
html>body .yourclass { }
/* Modern browsers (not IE 7) */
@odenijs
odenijs / Timespan calculation
Created July 31, 2013 13:28
Simple timespan calculation
/*
Input parameter is the UNIX timestamp
of the starting date.
The second parameter is optional -
It's value is the ending date,
also UNIX timestamp. If this
parameter is not given, the
default date is current date.
*/
function duration($start,$end=null) {
@odenijs
odenijs / Render partial view as string
Created August 13, 2013 13:10
Render a partial view as a string
/// <summary>
/// Renders the partial view to string.
/// </summary>
/// <param name="context">The context.</param>
/// <param name="partialViewName">Partial name of the view.</param>
/// <param name="viewData">The view data.</param>
/// <param name="tempData">The temp data.</param>
/// <returns></returns>
public static string RenderPartialViewToString(ControllerContext context, string partialViewName, ViewDataDictionary viewData, TempDataDictionary tempData)
{