If you are new to CSS, like I am, probably you asked yourself whether or not you should be using
px,emto define fonts and px or % for width and height.After some research I found out some interesting answers. But, pls feel free to share yours.
Basically, in theory, using
eminstead ofpx…
http://www.eworldui.net/blog/post/2011/01/07/Using-Razor-Pages-with-WebForms-Master-Pages.aspx
For those who want to slowly convert any web forms .net proj into MVC 3/4
Just came across an interesting problem:
I wanted to use MVC 4.0 within a legacy asp .net website project ( not a web application) using Visual Studio 2010 and Razor. I have all MVC versions installed on my machine.
So first I added/registered all MVC assemblies to web.config:
<add assembly="System.Data.Linq, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
<add assembly="System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.Abstractions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.Helpers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.Routing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
Also added to the <pages> node:
<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.Routing” />
<add namespace=”System.Web.WebPages” />
</namespaces>
<!——>
<controls>
<add tagPrefix=”asp” namespace=”System.Web.UI” assembly=”System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35” />
<add tagPrefix=”asp” namespace=”System.Web.UI.WebControls” assembly=”System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35” />
</controls>
And add the correct <httpmodules> :
<httpModules>
<!—<add name=”HttpCompressModule” type=”Ngd.DreamTeam.Football.Web.Compression.HttpModule,Ngd.DreamTeam.Football.Web”/>—>
<add name=”ScriptModule” type=”System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35”/>
<add name=”UrlRoutingModule” type=”System.Web.Routing.UrlRoutingModule, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a”/>
</httpModules><modules runAllManagedModulesForAllRequests=”true”>
<add name=”UrlRoutingModule” type=”System.Web.Routing.UrlRoutingModule, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a”/>
<remove name=”ScriptModule” />
<add name=”ScriptModule” preCondition=”managedHandler” type=”System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35” />
</modules>
Under <handlers> :
<add name=”UrlRoutingHandler”
preCondition=”integratedMode”
verb=”*” path=”UrlRouting.axd”
type=”System.Web.HttpForbiddenHandler,
System.Web, Version=2.0.0.0, Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a” />
Then merge the global asax and put the methods all on the global.asax.cs even if they are on the Global.asax .
So Global.asax should look like this :
<%@ Application Language=”C#” CodeFile=”Global.asax.cs” Inherits=”MvcApplication” %>
and the Global.asax.cs like this :
public partial class MvcApplication : System.Web.HttpApplication
{
public static void RegisterGlobalFilters(GlobalFilterCollection filters)
{
filters.Add(new HandleErrorAttribute());
}
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute(“{resource}.axd/{*pathInfo}”);
routes.MapRoute(
“Default”, // Route name
“{controller}/{action}/{id}”, // URL with parameters
new { controller = “Home”, action = “Index”, id = UrlParameter.Optional }
);
}
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
RegisterGlobalFilters(GlobalFilters.Filters);
RegisterRoutes(RouteTable.Routes);
}
protected void Session_Start(object sender, EventArgs e)
{
// This is the default setting for displaying marketing modals
SessionManager.SessionManagerInstance.ShowMarketingMessage = true;
}
protected void Application_Error(object sender, EventArgs e)
{
// all the legacy stuff
}
protected void Session_End(object sender, EventArgs e)
{
Session.Clear();
Session.Abandon();
}
protected void Application_End(object sender, EventArgs e)
{
}
}
Then created a folder Views on the root of the project and put the controllers classes into a folder called Controllers inside the App_Code folder ( If the controllers class are outside the App_Code project MVC will not work).
After all this the project did not work so after a couple of hours I found out that the virtual path ( on VS right button properties on top of the website node) cannot contain the character ‘.’ . My virtual path was something like “project.web” . When I removed this I successfully added MVC 4.0 to a legacy website asp .net project.
The problem:
Custom Info box does not appear on explorer when a marker is clicked when using google maps API javascript version 3.0 .
The solution:
This issue only happens on explorer and you can sort it out simply removing the opacity filter and the transparency :
#map_canvas div { filter: none !important ; background: transparent !important ; }
.Net Roles were not working as they were supposed.
I was getting empty Roles on Roles.IsUserInRole and Roles.GetRolesForUser.
[Authorize(Roles = “Administrator”)] was not working properly on the controller action methods. After a little bit of searching I found out that actually it was something missing on the web.config for the Roles to work on IIS7. So the solution simply is adding this web.config stuff under system.webserver -> modules:
<remove name=”FormsAuthentication” />
<add name=”FormsAuthentication” type=”System.Web.Security.FormsAuthenticationModule” />
<remove name=”UrlAuthorization” />
<add name=”UrlAuthorization” type=”System.Web.Security.UrlAuthorizationModule” />
<remove name=”DefaultAuthentication” />
<add name=”DefaultAuthentication” type=”System.Web.Security.DefaultAuthenticationModule” />
<remove name=”RoleManager” />
<add name=”RoleManager” type=”System.Web.Security.RoleManagerModule” />
http://stackoverflow.com/questions/991045/asp-net-authentication-with-roles-in-iis7-integrated-mode-for-static-content
This is a message to anybody considering using MVC. Especially 3 with Razor. Do it.
You won’t regret it, it’s fast, beautiful and razor makes it very easy to manage the design side of things.
When I have several e-commerce sites running on it then I’ll know more, so I’ll blog along the way.
(Source: makit)
Introduction
Recently I’ve been started a new MVC 3 app which is to have lot’s of components so I decided to go down the Dependency Injection route. This, for those who are hazy, is a OO design pattern for decoupling components.
I did some research (read, Google) and thought I’d go with …
(Source: makit)
I found out a lot of articles talking about boxing and unboxing but none of them explains when is good to use this technique.
On Msdn pages I found this definition:
“Boxing is the process of converting a value to the type object or to any interface type implemented by this value type. When the CLR* boxes a value type, it wraps the value inside a System.Object and stores it on the managed heap. Unboxing extracts the value type from the object. Boxing is implicit; unboxing is explicit. The concept of boxing and unboxing underlies the C# unified view of the type system, in which a value of any type can be treated as an object”
The term boxing refers an implicit casting and Unboxing is refers to explicit casting:
//Boxing
int i = 5;
object o = i; // Implicit Casting
//Unboxing
int j = (int)o; //Explicit Casting
Assume that you are working in a team of 3 developers each working on a different class. You need 3 classes to be implemented:
MyPoint - Defines a 2D point - Developer 1
My3dPoint - defines a 3D point - Developer 2
MyPrinter - Print the information of the other 2 classes - You
So the code for dev 1 and 2 will be :
//Developer 1
namespace Points{
public class MyPoint{
public int x;
public int y:
}
public class Starter{
MyPoint p = new MyPoint();
p.x= 4;
p.y = 5;
Utility.PrintInfo(p);
}
}
//Developer 2
namespace Points{
public class My3DPoints{
p.x = 3;
p.y = 4;
p.z =
}
So the class printer will use boxing and unboxing so its generic for all different class implementations.
namespace Printer
{
public class MyPrinter
{
public void PrintInfo(Object o) //Boxing is done here
{
if(o is MyPoint)
{
MyPoint p = new MyPoint();
p = (MyPoint)o; // Unboxing
Console.Writeline(“The point is ({0}, {1})”, p.x, p.y);
}
else if(o is My3DPoint)
{
My3DPoint p = new My3DPoint();
p = (My3DPoint)o; // Unboxing
Console.Writeline(“The point is ({0}, {1}, {2})”, p.x, p.y, p.z);
}
}
}
}
This article is an example how to use boxing and unboxing, however you can solve this problem using generics. I'll write a post about that later.
In this article I will talk about the differences between value types and reference types in c# .
This article assumes a previous knowledge on C# and on the ability to define classes and properties.
To differentiate value types from reference types we can pick an example of each type: Classes and Structs.
We can define a struct simply saying that structs are cut-down classes meaning that structs don’t have finalizers and don’t support inheritance.
Here is an example of a struct:
struct Point
{
private int x, y; // private fields
public Point (int x, int y) // constructor
{
this.x = x;
this.y = y;
}
public int X // property
{
get {return x;}
set {x = value;}
}
public int Y
{
get {return y;}
set {y = value;}
}
}
There is another difference between structs and classes. Structs are value types and classes are reference types. When a value type instance is created a single space in memory is used to allocated to store the value. Primitive types such as int, float, bool and char are also value types, and work in the same way.
Reference types need 2 spaces allocated in memory : a reference to the object and the object itself.
Suppose Form is a class and Point is a struct:
Point p1 = new Point(); // Point is a *struct*
Form f1 = new Form(); // Form is a *class*
In the first case only one space is allocated in memory for p1 whereas, in the second case two spaces are allocated, one for the Form object and other for it’s reference f1.
If we copy both objects using variables:
Point p2 = p1;
Form f2 = f1;
p2 will be an independent copy from p1 with it’s own separated fields. f2 will be a new reference of the object Form, f2 is simply a copy of the reference f1. Now we have 2 references pointing to the same object.
This is really interesting on the passing parameters to methods. As you must know all method parameters are passed by value (by default) in C# meaning that they are implicitly copied when passed to the method.
For value-type parameters this means that an independent is created like we saw with p2 and for reference types this means copying a reference.
Point myPoint = new Point (0, 0); // a new value-type variable
Form myForm = new Form(); // a new reference-type variable
Test (myPoint, myForm); // Test is a method defined below
void Test (Point p, Form f)
{
p.X = 100; // No effect on MyPoint since p is a copy
f.Text = “Hello, World!”; // This will change myForm’s caption since
// myForm and f point to the same object
f = null; // No effect on myForm
}
Assign null to f has no effect because f is a copy of a reference and we have only erased the copy.
When passing by “reference”, the method interacts directly with the caller’s arguments. In the example below, you can think of the parameters p and f being replaced by myPoint and myForm:
Point myPoint = new Point (0, 0); // a new value-type variable
Form myForm = new Form(); // a new reference-type variable
Test (ref myPoint, ref myForm); // pass myPoint and myForm by reference
void Test (ref Point p, ref Form f)
{
p.X = 100; // This will change myPoint’s position
f.Text = “Hello, World!”; // This will change MyForm’s caption
f = null; // This will nuke the myForm variable!
}
In this case, assigning null to f also makes myForm null, because this time we’re dealing with the original reference variable and not a copy of it.
-
CSS - when to use em, px, %?
If you are new to CSS, like I am, probably you asked yourself whether or not you should be using
px,emto define... -
JavaScript functions - defining a function
To define a function, use var like you do for declaring a variable:
For ex., print hello twice:
var i =...
-
home
-
Some Quick Observations on MegaUpload
Yesterday an international police operation resulted in the shutdown of MegaUpload and the arrest of at least...