0

I am new in how to used MVC Pattern in asp.net. In general web Application I have initialize configuration which are common on website level

Like,

public partial class Default : MyBaseClass
{
}

public class MyBaseClass : System.Web.UI.Page
{

 public override OnDo()
{

}
}

Please ignore if any spell mistake. In OnDo() function I initialize StoreClass which properties can be access whole application.

This scenario how I achieve in asp.net MVC

4
  • 1
    Have you tried reading any books or websites on ASP.NET MVC? Commented May 1, 2012 at 3:59
  • Create a static class and set the properties of the class in the app_start. More about app_start here stackoverflow.com/questions/2058621/… Commented May 1, 2012 at 4:04
  • I have general knowledge about how MVC Pattern Work. Commented May 1, 2012 at 4:05
  • @AkilVhora - general knowledge of the MVC pattern will give you almost no help understanding how ASP.NET MVC works. Go to asp.net/mvc and start at the beginning. Commented May 1, 2012 at 5:23

3 Answers 3

1

You could use the global.asax events

http://www.techrepublic.com/article/working-with-the-aspnet-globalasax-file/5771721

Sign up to request clarification or add additional context in comments.

Comments

0

In ASP.Net project, you can place your configuration information in web.config. However, I prefer to place my config in an XML file and deploy it with the ASP.Net to web site. Here is one example to define my configuration class:

public class MyAppConfig {
  private static _config = null;
  // Configuration is a simple class with a list of properties
  public static Configuration Configuration {
     if (_config == null ) {
         _config = new Configuration();
         // parse XMl file and set properties
     }
     return _config;
  }
}

In your case, you can use MyAppConfig to get web application level configuration properties:

public class MyBaseClass : System.Web.UI.Page
{

  public override OnDo()
  {
      Configuration myConfig = MyAppConfig.Configuration;
      // use properties ....
  }
}

The advantage of placing configuration in your own XML file is that this component can be used in other apps such as console app with very little changes. However, you cannot write changes to the XML file in Web applications. Normally, I place writable information in databases to resolve the issue.

Comments

0

For an event to be triggered before every action, you can do this.

Define a base controller and use it for all your controllers.

public class BaseController : Controller
{
    protected override void OnActionExecuting(ActionExecutingContext context)
    {
    }
}

Your controllers will look like this:

public class MyController : BaseController

OnActionExecuting will get fired before each action

For a session level or application level event, you should use global.asax

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.