• Code
  • Tags
  • Users
  • Titles
  • Log in
  • Feedback
  • FAQ
Share Code
Welcome to ForkCan.com

ForkCan is all about sharing code in a social way.

Discuss, debate or argue with other devs about their or your own code.

Give other devs feedback or make a Fork (Make a better version of a shared code).

Rate the code, if you use the code mark it as used so others can see if the shared code is used by someone.

Help each other to be better devs and to be more productive.


Features not working yet:

Flag a post


QR Code

Tiny Url

http://4kcan.com/s/MjI2

Related Code
Unity Service Locator for ASP.NET MVC 3.0 Beta 1
Google Analytics helper for ASP.NET Razor
UnitOfWork Action filter for ASP.NET MVC and nHibernate
StringFormat Extension method for HtmlHelper ASP.NET MVC
Generic Entity Framework 4.0 Base Repository
ForEach Extension method for IEnumerable<T>
Using DynamicObject to get a value from the Request.Params
Invoke Extension Method
Use of Extension methods to hide "infrastructure code"
PagedList class and paging code for ASP.Net MVC (Nothing new but kind of usefull.)
Null Dot "Operator" Extension Method
Fork of GZIP your Actions in MVC if not used as standard in IIS7 or only use IIS6
Generic Entity Framework 4.0 Base Repository with Paging
Unity Controller Factory for ASP.NET MVC 3.0
Generic linq-to-sql repository
WCF RIA Services Unity 2.0 DomainService Factory
A Default Entity Framework 4.0 ObjectContext Factory
Email validation with Regular Expression
Reflection dynamically get private fields or properties
GZIP your Actions in MVC if not used as standard in IIS7 or only use IIS6
Custom C# exception class
Url Validation with Regular Expression
Method to hash passwords
Number of sealed / unsealed types in the framework

Make sure the web.config pages/namespace can be used together with ASP.NET MVC 3 P1 and Razor

Make sure namespaces will be imported into every view when using ASP.NET MVC 3.0 Preview 1

0
770 0 0 0 0 0

using System.Configuration;
using System.Web.Configuration;
using Microsoft.WebPages.Compilation;

namespace Infrastructure.Configuration
{
    public static class PreApplicationStartCode
    {
       public static void ImportNamespace()
       {
           var pagesSection = ConfigurationManager.GetSection("system.web/pages") as PagesSection;

           if (pagesSection == null)
               return;

           foreach (NamespaceInfo namespaceToImport in pagesSection.Namespaces)
           {
               CodeGeneratorSettings.AddGlobalImport(namespaceToImport.Namespace);
           }  
       }
    }
}

How to use the code:

Add the following code into the assembly containing the above code:

[assembly: PreApplicationStartMethod(typeof(PreApplicationStartCode), "ImportNamespace")]

It will make sure ASP.NET 4.0 will make a call to the ImportNamesapce method long before Application_Start is called, read more about it here.

Make sure your ASP.NET MVC project adds a reference to the project where the above code is added to.

Now you can do use the pages/namespace section in web.config to globally import namespaces into the views. Example of the section in web.config:

<system.web>
    <pages>
      <namespaces>
        <add namespace="System.Web.Mvc" />
        <add namespace="System.Web.Mvc.Ajax" />
        <add namespace="System.Web.Mvc.Html" />
        <add namespace="System.Web.Routing" />
        <add namespace="Infrastructure.WebHelpers"/>
      </namespaces>
    </pages>
</system.web>

Note: The above solution will add Web Form namespaces too because it will take the namespaces added to the global configuration files.


Share: twitter | facebook   Action: used | fork | flag

.net

Mark '.net' tag as 'like'

Mark '.net' tag as 'ignore'

aspmvc

Mark 'aspmvc' tag as 'like'

Mark 'aspmvc' tag as 'ignore'

aspnet4

Mark 'aspnet4' tag as 'like'

Mark 'aspnet4' tag as 'ignore'

c#

Mark 'c#' tag as 'like'

Mark 'c#' tag as 'ignore'

razor

Mark 'razor' tag as 'like'

Mark 'razor' tag as 'ignore'


 @fredrikn "I'm the master"
2.81k
August 04, 2010 11:18 AM
edited August 04, 2010 11:36 AM

Fork

 Make sure the web.config pages/namespace can be used together with ASP.NET MVC 3 P1 and Razor -  @fredrikn Wednesday 04, 2010 11:18 AM


0 Feedback


You must log in before you can give any feedback


0 Discussion(s)

Newest Oldest

You must log in before you can post a comment

Squeed
Made by: Fredrik Normén 2010