How to enable true intellisense on javascript files
February 9th, 2010Hi all,
I have just read a post I thought I should share with you. You may have already heard about jquery and the fact that with the version 1.3, there was a vsdoc file that you could download so that you could have intellisense while writing javascript using jquery. Now, a patch is released for Visual Studio which, enables support for vsdoc files. Not only for jQuery, but for any javascript file.
Here is the link to the original post : http://blogs.msdn.com/webdevtools/archive/2008/11/07/hotfix-to-enable-vsdoc-js-intellisense-doc-files-is-now-available.aspx
Here is the link to the jquery web site, where you can download the vsdoc file : jQuery web-site (look for the "Documentation: Visual Studio")
Of course, vsdoc are not supposed to be deployed. They exists only to help developpers.
How to improve your intranet ASP.NET web application performance ?
January 7th, 2010Hi,
Have you ever had a look on the number of request made by an intranet web application ? I put a premium on Intranet because I am talking about the windows authenticated web applications. Generally, for applications like these, we configure them to deny any anonymous user to connect to it. However, it means that every single file would need authentication, which is non sense : javascript files, css, pictures, . all these kind of file do not need authentication. That's why you should configure you application to allow anonymous users on them.
Why would it increase performance to disable authentication for them ? Because when using windows authentication, the browser sends a request as an anonymous user, the server replies that 401 (not allowed) and then, and only then, the browser sends a request as "you", and now you can get the file. It then means 2 request/response pairs for a single file. It make sense for pages, but not for style and scripts. IMHO, the best way is to put non sentive files in a folder. Typically, you should use the Themes functionality (even if you would have only one theme).
Now let's come to the practical point of view and allow non sensitive files to be access anonymously. For each folder with non sensitive data, you should add a web.config file like the following :
<?xml version="1.0"?>
<configuration>
<system.web>
<authorization>
<allow users="?"/>
</authorization>
</system.web>
</configuration>
It is now better but not enough. Indeed, there is also this script resources loaded by the ScriptManager. Since we cannot easily redirect the path to ScriptResource.axd and WebResource.axd, we have to change the root web.config file by adding the followings in the root configuration element :
<location path="WebResource.axd">
<system.web>
<authorization>
<allow users="?" />
</authorization>
</system.web>
</location>
<location path="ScriptResource.axd">
<system.web>
<authorization>
<allow users="?" />
</authorization>
</system.web>
</location>
Hope you liked the tip. See ya
How to make an HTTP proxy
October 24th, 2009As you have seen, I have recently updated my zeroconf codeplex project. This project not only contains an implementation of the DNS protocol and of the Bonjour protocol. It also contains an implmentation of the HTTP protocol to be able to send some HTTP request on UDP, which is not possible with the implementation given with the .NET Framework. At work, I have to check that a web application I developped works correctly with IE6 (yes, it still exists. unfortunately). Since I am on Windows 7, I thought it could be great to use IE6 as virtual app. I think you know where I want to come to. On a virtual machine, you have no access to the web development server started by visual studio. What I could have been doing is deploying to the virtual machine, which would mean installing IIS, configuring it, spend time to check the web.config. Well not a straight forward solution. So I told myself : What I need is a proxy, and I already have the HTTP protocol implementation !
Here is the code of the famous proxy :
public class Proxy
{
RestServer proxy;
string hostToRedirectTo;
static void Main(string[] args)
{
Proxy p = new Proxy(ushort.Parse(args[0]), args[1]);
p.Start();
Console.ReadLine();
p.Stop();
}
private void Stop()
{
proxy.Stop();
}
private void Start()
{
proxy.StartTcp();
}
public Proxy(ushort portToListenOn, string hostToRedirectTo)
{
proxy = new RestServer(portToListenOn);
this.hostToRedirectTo = hostToRedirectTo;
proxy.HttpRequestReceived += proxy_HttpRequestReceived;
}
void proxy_HttpRequestReceived(object sender, HttpRequestEventArgs e)
{
e.Request.Host = this.hostToRedirectTo;
e.Response = e.Request.GetResponse(true);
e.Response.Body.Position = 0;
}
}
As you can see, the solution is straight forward and is only a ten lines of code !!!
Bonjour Updated
October 23rd, 2009Hi everybody,
I have updated my zeroconf codeplex project. The main thing I have done is some refactoring. This project not only has a bonjour implementation, but also a server implementation. With such a server implementation, you can do almost anything you want. The only drop on this is that I can't deal with sessions. To understand what I am talking about, I would suggest you to download the new bonjour release and look at the Network.dll assembly. I promise I will give some more documentation about it. You already can have a look the documentation on the codeplex site.
Have fun !
Reusable singleton in ASP.NET Context
August 5th, 2009Hi everyone,
After reading Ayende Rahien's post, I told my self that I had to share my Http Singleton module I am using for some time now. This module enables me with a few lines of code to have a single instance of what ever I could want. If like Ayende, you are using NHibernate, you just would need to inherit from the code I'll give you to make your own HttpSessionModule, and thus have one session created by httpcontext. I use it to have not only an ObjectContext (I am using euss), but a service which hides this persistence layer.
Here is my abstract Http Singleton module implementation :
public abstract class HttpSingletonModule<T> : IHttpModule
{
#region IHttpModule Members
public void Dispose()
{
}
public void Init(HttpApplication application)
{
application.PostAuthorizeRequest +=
new EventHandler(application_AuthorizeRequest);
application.EndRequest +=
new EventHandler(application_EndRequest);
}
void application_EndRequest(object sender, EventArgs e)
{
HttpApplication application = sender as HttpApplication;
HttpContext context = application.Context;
if (context != null)
{
T instance =
(T)context.Items[typeof(T).AssemblyQualifiedName];
if (instance is IDisposable)
((IDisposable)instance).Dispose();
}
}
public static T Instance
{
get
{
return (T)HttpContext.Current.Items[typeof(T).AssemblyQualifiedName];
}
set
{
HttpContext.Current.Items[typeof(T).AssemblyQualifiedName] = value;
}
}
void application_AuthorizeRequest(object sender, EventArgs e)
{
HttpApplication application = sender as HttpApplication;
HttpContext context = application.Context;
if (context != null)
context.Items.Add(typeof(T).AssemblyQualifiedName,
CreateInstance(context));
}
protected abstract T CreateInstance(HttpContext context);
#endregion
}
As you may have understood now, To implement your module, it is quite easy. Here is the implementation I am using in a projet :
public class PortalServiceModule : HttpSingletonModule<PortalService>
{
protected override PortalService CreateInstance(HttpContext context)
{
if (context.User.Identity.IsAuthenticated)
return new PortalService(context.User.Identity.Name);
return new PortalService();
}
}
You see ? so few lines of code for such a simplicity of use : to get my portal service instance, I just have to call the static Instance property of my PortalServiceModule. How could it be simpler ?
Parameterized Modal Popup
Août 3rd, 2009Hello everyone,
Maybe some among of you ever had this issue : open a modal popup (here with AjaxControlToolkit), and being able to give it a parameter, the id of the control which opened the popup for example. It is entirely doable, it just need some code. The first thing to know it that with AjaxControlToolkit framework, there is a BehaviorID on any Extender. This property enables you to then manipulate this extender on the client side (in javascript). Let's have a look to the code before any explanation.
<asp:ModalPopupExtender runat="server" BehaviorID="myPopupBehavior" PopupControlId="myPopup" TargetControlId="dummyLB" /> <asp:Panel ID="myPopup" runat="server"> <asp:HiddenField runat="server" ID="myParameter" /> </asp:Panel> <asp:LinkButton ID="dummyLB" runat="server" style="display:none" /> <style type="text/javascript"> function openPopup(parameter) { $find("myPopupBehavior").show(); $get("<%= myParameter.ClientID %>").value=parameter; } </style>
After having seen the code, I guess you need some explanations. First of all, the first thing to know is that an AjaxControlToolkit extender always need a TargetControlID. I made an invisible LinkButton for that purpose. The second this to notice, is that in the panel which will be displayed, I have an hidden field. This is this field which would hold the value of my parameter. To assign my parameter, I made this javascript function which hides this assignment behavior. Thus, I have a reusable function to open that popup. Here is a sample use case :
<a onclick="openPopup('http://www.google.fr')>lien vers google</a>
With this code you also can have the value of your parameter on the server side because the hidden field is a server control !
Voilà, hope you enjoyed it.
jQuery Control Toolkit
June 6th, 2009Hello everyone,
It's been a long time since I posted something on my blog. I was a little busy with my work. But this work enables now me to introduce you a new codeplex project : jQuery Control Toolkit. The aim of the project is to be able to use jQuery trough extenders in ASP.NET, but more globally, it adds new functionalities as jQuery plugins. The project is not so detailed yet, but if you can't wait for a description of each functionality, just have a look at the source code, there is a web application project which uses each (main) functionality. There are also more functionalities in the javascript source file jQuery.ACT.js, but, it is not documented at all (yet).
Have fun,
Powershell for Visual Studio
March 23rd, 2009Hello,
Here is my new project : Powershell for Visual Studio. There is already syntax coloration, and basic intellisense (available cmdlets, with their help). Currently, it seems that the VS2008 SDK is needed to make it work. This will be solved in the next release...
Have fun !
Powershell for Visual Studio
XNA Designer 0.1
February 24th, 2009Hello everyone,
I've updated my XNA codeplex project. Now, the designer works, is (more or less) beautiful. Moreover, you may also download a component library containing game components : cameras, model viewer, cube, stairs, wall, ...
You can have a look at this designer on the wiki home page of the project.
You want to try it by yourself, go to the release.
Bonjour MEF
February 7th, 2009Hello everyone,
Do you know MEF (Managed Extensibility Framework) ? It is a new library in .NET that enables greater reuse of applications and components. Using MEF, .NET applications can make the shift from being statically compiled to dynamically composed. I let you go to codeplex to get more information.
MEF is based on catalogs. There are a DirectoryCatalog, an AssemblyCatalog, ... Well, I am proud to introduce you to a BonjourCatalog.
For this, still the same address : http://www.codeplex.com/zeroconf.
"What is the aim, you may ask ?" It simply enables to detect bonjour services using MEF.
I have not published any release regarding this BonjourCatalog yet, but it wont last.
Concrete Singleton pattern implementation in .NET
January 14th, 2009Hello everybody,
A pattern we regularly find is the singleton pattern. What I suggest you is a .NET implementation. This one deals with a singleton context dependent (singleton by ASP.NET context, by WCF context, by thread, for the whole application)
public class Singleton<T>
{
private Singleton()
{
if (CreatingInstance != null)
CreatingInstance(this, EventArgs.Empty);
}
private static T instance;
[ThreadStatic]
private static T threadInstance;
private static object instanceLock = new object();
public static T Instance
{
get
{
//ASP.NET case
T instance;
if (HttpContext.Current != null)
{
if (UseContextInstance)
instance = (T)HttpContext.Current.Items[typeof(T).AssemblyQualifiedName];
else
instance = (T)HttpContext.Current.Application[typeof(T).AssemblyQualifiedName];
if (instance == null)
{
instance = new Singleton<T>().SingletonInstance;
if (UseContextInstance)
HttpContext.Current.Items[typeof(T).AssemblyQualifiedName] = instance;
else
HttpContext.Current.Application[typeof(T).AssemblyQualifiedName] = instance;
}
return instance;
}
if (OperationContext.Current != null)
{
throw new NotImplementedException();
if (instance == null)
{
HttpContext.Current.Items[typeof(T).AssemblyQualifiedName] = new Singleton<T>().SingletonInstance;
}
return instance;
}
//In case of no HttpContext nor OperationContext
if (UseContextInstance)
{
if (Singleton<T>.threadInstance == null)
Singleton<T>.threadInstance = new Singleton<T>().SingletonInstance;
}
else
{
if (Singleton<T>.instance == null)
{
lock (instanceLock)
{
if (Singleton<T>.instance == null)
Singleton<T>.instance = new Singleton<T>().SingletonInstance;
if (Singleton<T>.instance == null)
TryActivate(out Singleton<T>.instance);
}
}
}
return Singleton<T>.instance;
}
}
private static void TryActivate(out T p)
{
try
{
p = Activator.CreateInstance<T>();
}
catch (MissingMethodException) { p = default(T); }
}
public T SingletonInstance { get; set; }
public static event EventHandler CreatingInstance;
/// <summary>
/// Set this property to <see cref="true" /> to have your singleton dependant on your context :
/// - one per thread in Windows Forms/WPF
/// - one per Context in ASP.NET
/// </summary>
public static bool UseContextInstance { get; set; }
}
Last codeplex project address change
January 7th, 2009Hello,
I've changed my last codeplex project address. Why ? only because I'm adding this uPnP implementation, and is totally different from the bonjour protocol.
Here is the new address :
http://www.codeplex.com/zeroconf
See you
Bonjour and DNS .NET implementation
January 2nd, 2009Hello,
I've recently published on codeplex a partial object DNS protocol implementation and an implementation of Apple's Bonjour protocol. You may ask me why implement this DNS protocol whilst a .NET Dns class exists. First of all, because the Dns class is based on Win32 API, which, I don't want. Secondly, because my DNS implementation is mDNS (multicast DNS) compliant, and Bonjour relies on this protocol. At last, and not the least, for fun !
Let's stop talking and discover it...
Posts en français
Janvier 2nd, 2009Bonjour à tous,
Pour les anglophobes, ou ceux qui ne veulent pas se fatiguer à lire l'anglais, sachez qu'à partir de maintenant, vous pourrez consulter un blog en français à cette adresse : http://blog.dragon-angel.fr
Assemblies EmbeddedResources with .NET 3.5 SP1
September 28th, 2008Hello everyone,
It's been a long time since posting. I've just installed the new SP1 for VS2008, and .NET 3.5 SP1. Then, I've been struggling with assemblies and embedded resources. Before installing it, if I had an assymbly with the default namespace Products.Repositories, and a file named Domain.Mapping.xml, it used to generate a manifest with a name like that : Products.Repositories.Resources.Domain_mapping. Now, it generated a manifest with the following name : Products.Repositories.Domain.Mapping.xml. I personnally find it more logical since in it does not alter the file name or nor it adds a Resources in the namespace. But, it would have also been great to be aware of that change... Now, you are ;)