Solved

how do i specify master page programtically under asp.net mvc 4

Posted on 2014-12-30
1
137 Views
Last Modified: 2015-01-01
how do i specify the master page programtically,for example,i'd like main page goes to a out of service from 8:00 pm to 8:00am,& set a filter out of service  from 8:00 pm to 8:00am as well.in addtion ,i have a ip database api,i'd like restrict the ip only from my country to access,otherwise the main page goest to "bad request" page.how do i do this programtically?
many thanks & best regards
ken
0
Comment
Question by:ken yup
1 Comment
 
LVL 25

Accepted Solution

by:
apeter earned 500 total points
ID: 40525177
You can check below 2 conditions in one place.

1. Timing
2. Ip from ips database

put this code block in the Application_BeginRequest of the Global.asax

void Application_BeginRequest(object sender, EventArgs e)
      {
          if (DateTime.Now <is greater than 8 am and lesser than 8 pm>) AND (Request.UserHostAddress <is in your ip datadatabase>)) //replace the <text> to a c sharp syntax
          {
              if (!Request.IsLocal)
              {
                  HttpContext.Current.RewritePath("<Your Maintenance Page >");
              }
          }
      }
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question