Thursday, January 1, 2015

DNN Custom Error Pages

[Custom Errors] 

Default error pages may expose a lot of information, Like the language and the server you use, and such Info. could be used by malicious users to attack your site and your server.

Also default error pages look very ugly and outdated design, which may harm your brand.

So It's always recommended to use custom error pages..

So, How Could I display a custom error page in DNN when error occurs ?

To Disable DNN Error Handling, and Let Errors Bubble..
Host Settings >> Appearance >> Un-Check "Use Custom Error Messages? "


To Redirect Users To, Can be aspx page, but I prefer HTML
Then Create HTML Page at the root with Style


Then in Enable CustomErrors in Web.Config :
    <customErrors mode="On">
      <error statusCode="500" redirect="/MyCustomError.html"/>
      <error statusCode="404" redirect="/MyCustomError.html"/>
      <error statusCode="403" redirect="/MyCustomError.html"/>
    </customErrors>
  
Also You can Override IIS Error Pages and Redirect to your Custom Error Pages using the below web.config snippet

    <httpErrors>
      <remove statusCode="404" subStatusCode="-1"/>
      <error statusCode="404" prefixLanguageFilePath="" path="/MyCustomError.aspx" responseMode="ExecuteURL"/>
      <remove statusCode="403" subStatusCode="-1"/>
      <error statusCode="403" prefixLanguageFilePath="" path="/MyCustomError.html" responseMode="ExecuteURL"/>
    </httpErrors>

Thursday, December 26, 2013

LINQ to Entities CLR Methods Mapping

It's very useful to have this in mind when you write lambda expressions or use LINQ to Entities

For example, you can't compare GUID to string using ToString() Method in the lambda expression as ToString() Doesn't have a mapping, but you can use New GUID 

http://msdn.microsoft.com/en-us/library/bb738681(v=vs.110).aspx

Thursday, December 5, 2013

Useful Entity Framework Tutorials

It's rare to find a complete tutorials' series like W3Schools but this site make a great series for Entity Framework http://www.entityframeworktutorial.net/

Tuesday, October 8, 2013

Post to twitter programatically with 3 lines of Code!

  1. Create a new web application
  2. using Nuget manager, download/install Tweetsharp
  3. Create a twitter application by visiting https://dev.twitter.com/apps/new
  4. Go to your twitter app settings, and make sure it's a read/write app
  5. Go to "Reset Keys" tab and reset keys, so the permission of read/write works with the new keys
  6. Generate Access Token and the first tab in your twitter settings
  7. Write the following Code, *Replace Dashes with your app keys, from the previous steps
======================================
using TweetSharp;
        //Store Keys
        string consumerKey = "-------";
        string consumerSecret = "-------";
        string accessToken = "-------";
        string accessTokenSecret = "-------";
        //Authenticate with twitter as your app.
        var service = new TwitterService(consumerKey, consumerSecret);
        service.AuthenticateWith(accessToken, accessTokenSecret);
        //Post Tweet
        var status = service.SendTweet(new SendTweetOptions { Status = "My Second #Tweet from Code :D" });
======================================
-- You can use the status variable to know the id of you posted status etc.

Thursday, April 11, 2013

How to make my desktop less destractive

I Simply use virtual desktops program, which give me many desktops, if you use linux, you may be familiar with this technique .. Instead of having one desktop full of programs' windows you can have many desktops each one have a set of programs, so you can switch context and environment easily

for example, browser with social networks and E-mail clients etc. on one desktop
and the other desktop contains other browsers to test my web application and my media player

Application Here http://technet.microsoft.com/en-us/sysinternals/cc817881.aspx

Sunday, March 31, 2013

Less for Dot Net - Asp.net

Introduction

Just hit an interesting utility, LESS Compiler for .net (asp.net)
So you can leverage the power of less (Dynamic CSS) in your .net web applications

Usage

Just add the following to the Web.config
<add type="dotless.Core.LessCssHttpHandler,dotless.Core" validate="false" path="*.LESS" verb="*" />
<section name="dotless" type="dotless.Core.configuration.DotlessConfigurationSectionHandler,dotless.Core" />
 
So, now you added a handler for .less files
 
Then configure it
<dotless minifyCss="false"
 cache="true" />   

*You can also use it from the code
Less.Parse("div { width: 1 + 1 }");
which will produce 
div {
  width: 2;
}
 

More Here
http://www.dotlesscss.org/