Subscribe to Feed

 

You can use Microsoft.Web.Administration namespace to create a binding and set the certificate hash. Let us say you are trying to add a new binding to a website “MySite” with a new SSL certificate hash “MyCertHash”, here is what you have to do to achieve this

ServerManager serverManager = new ServerManager();
serverManager.Sites["MySite"].Bindings.Add("*.443:", MyCertHash, "MyCert");

The bindings member configures binding information for an IIS 7.0 Web site. You can also add multiple bindings to a website or use similar approach to add other bindings.

 

On some occasions you might want to deploy the Asp.Net MVC application to avoid compiling it yourself etc. You can achieve this by following the below steps

  1. Create an ASP.NET website project in Visual Studio
  2. Add a reference to the System.Web.Mvc.dll (and any other DLLs that your application might need)
  3. Copy the web.config from regular ASP.NET MVC project and make all additional changes that you  need for your web application.
  4. Place all your controllers and models in ~/App_Code folder.
  5. Place all your views ~/Views/Home/Index.aspx (The usual location where Views are in a regular MVC application)
  6. Run the application and you are good to go.

Of course there are couple of limitations to this approach like You will not get the addition tooling support from Visual Studio that it usually provides for an MVC.

 

On some occasions you might want to use retail versions of Asp.Net JavaScript libraries while debugging your code. (For starters, when in debug mode in Visual Studio, you are not using the release versions, instead you are using debug versions of the libraries). To achieve this all you have do is set the ScriptMode property of the ScriptManager control to “Release“.  This will allow the release Asp.Net Ajax library to be used in debug mode.

 

<asp:ScriptManager ScriptMode="Release" /> 

 

On some occasions you would want to run some code for every change in the configuration file, like reload the cache etc.. A change in web.config prompts the app domain to reload. So one should be able to look for application domain shutdown reason to verify a configuration change. Here is how you do can do it

In you Global.asax.cs file add the following code

protected void Application_End(object sender, EventArgs e)
{
    if (HostingEnvironment.ShutdownReason == 
                           ApplicationShutdownReason.ConfigurationChange)
    {
        // Do Something
    }
}

Hope this helps someone.

 

On some occasions, you wish to initialize your Asp.net application even before it receives its first hit to get rid of any over heads like creating application domain, initializing the .net runtime environment etc.. To achieve this you can use aspnet_compiler to pre-compile ‘in-place’, so that in effect the application is primed. Compiling ‘in-place’ the behavior of making multiple requests to the application, thus causing regular compilation.

// The following command compiles the "MyWebSite" Asp.Net application in place.

Aspnet_compiler -v /MyWebSite

 

The ASP.NET Compilation tool (Aspnet_compiler.exe) enables you to compile an ASP.NET Web application, either in place or for deployment to a target location such as a production server. In-place compilation helps application performance because end users do not encounter a delay on the first request to the application while the application is compiled. For more information on Asp.Net compilation tool refer to the MSDN article here.

 

For the starters, Adaptive control behavior is control behavior that is customized for target devices. ASP.NET provides an adaptive architecture that allows key life cycle stages of a control to be intercepted and substituted with custom behavior. A common example of adaptive control behavior is adaptive rendering where an ASP.NET Web page is rendered specific to the browser or markup. This is especially useful for writing applications that support browsers that use different markup languages. for more information refer to the MSDN article here.

Sometimes, when you are writing a custom control that uses Asp.Net control controls like menu etc which has Adaptive rendering built in, you might wish to turn that behavior off for what ever reason. (May be you have your own adaptive rendering logic and wish to display the menu in a different way than that of default Asp.Net’s!) Here is a simple trick to block default adaptive rendering in your custom control: Override the ResolveAdapter method in the custom control to return null always.

 

protected override ControlAdapter ResolveAdapter()
{
    return null; // instead of base.ResolveAdapter()
}

 

That’s it and you are all set.

Hope this helps some one.

10Aug

31 Days of Refactoring

Posted by admin as Random, Visual Studio

 

Take a look at this very interesting blog post series - 31 days of refactoring

http://www.lostechies.com/blogs/sean_chambers/archive/2009/07/31/31-days-of-refactoring.aspx

The various refactoring “methods” are getting more complex and interesting as the series continues.

IMHO, This is must read for all developers.

 

In a code behind file (like .cs file), one can use aliases for the namespaces like

using myAlias = System.MyNamespace;

But to achieve the same functionality in an .aspx page you can use something like this

<%@ Import Namespace="myAlias=System.MyNamespace" %>

Note: There should not be any spaces in the namespace value. For example you cannot use something like Namespce=”myalias = System.MyNamespace”

Hope this helps.

 

Assembly Binding Log Viewer (Fuslogvw.exe) aka. Fusion log viewer is your best friend when it comes to find your way through in resolving the “Could not load file or assembly” errors. The Assembly Binding Log Viewer displays details for assembly binds. This information helps you diagnose why the .NET Framework cannot locate an assembly at run time. These failures are usually the result of an assembly deployed to the wrong location, a native image that is no longer valid, or a mismatch in version numbers or cultures.

Refer to this MSDN article for complete information related to The Assembly Binding Log Viewer.

 

Mscorcfg.msc  is a Microsoft Management Console (MMC) snap-in that enables you to manage and configure assemblies in the global assembly cache (GAC), adjust code access security policy and adjust remoting services. It is supported in all versions of .Net Framework Prior to .Net framework 4.0. But, In the .NET Framework versions 1.0 and 1.1, Mscorcfg.msc is installed with the NET Framework redistributable package. In the .NET Framework 2.0 and later versions, Mscorcfg.msc is installed with the .NET Framework 2.0 Software Development Kit (SDK).  Reefer the following MSDN article for more information http://msdn.microsoft.com/en-us/library/2bc0cxhc(VS.100).aspx.

In .Net Framework 4.0, Machine wide security policy has been eliminated, and hence no Mscorcfg. Refer to following MSDN article for more information http://msdn.microsoft.com/en-us/library/dd233103(VS.100).aspx related to security changes in the .NET Framework 4.

 

 

Subscribe to Feed

Categories

Links

Dev Jobs