I have a requirement to show some of that database information in the layout view of my MVC application.
I was thinking that if I did this in the Application_Start()
method, and assigned to a static class with a static value, the view would be able to access those variables and display them...but them show up blank.
Here is the Application_Start()
:
NWatchEntityApplication nWatchApp;
protected void Application_Start()
{
var assemblies = BuildManager.GetReferencedAssemblies().Cast<Assembly>();
AreaRegistration.RegisterAllAreas();
GlobalConfiguration.Configure(WebApiConfig.Register);
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
BundleConfig.RegisterBundles(BundleTable.Bundles);
nWatchApp = new NWatchEntityApplication(GetNWatchConfig());
SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder(nWatchApp.Configuration.NWatchDatabase);
Infrastructure.ApplicationInfo.NWatchDatabaseCatalog = builder.InitialCatalog;
Infrastructure.ApplicationInfo.NWatchDatabaseServer = builder.DataSource;
var context = nWatchApp.GetDbContext();
builder = new SqlConnectionStringBuilder(context.DatabaseConnectionString);
Infrastructure.ApplicationInfo.EntityDatabaseCatalog = builder.InitialCatalog;
Infrastructure.ApplicationInfo.EntityDatabaseServer = builder.DataSource;
var webApiContainer = new Container();
webApiContainer.Options.DefaultScopedLifestyle = new WebApiRequestLifestyle();
RegisterTypes(webApiContainer);
webApiContainer.RegisterWebApiControllers(GlobalConfiguration.Configuration);
webApiContainer.Verify();
GlobalConfiguration.Configuration.DependencyResolver =
new SimpleInjectorWebApiDependencyResolver(webApiContainer);
}
Here is the static class to hold the info:
public static class ApplicationInfo
{
public static string NWatchDatabaseServer { get; set; }
public static string NWatchDatabaseCatalog { get; set; }
public static string EntityDatabaseServer { get; set; }
public static string EntityDatabaseCatalog { get; set; }
}
And here is the portion of the view that should be able to access these variables:
<div class="footer">
<div class="footer-inner">
<div class="footer-content">
<p>@BranchCircuits_Web.Infrastructure.ApplicationInfo.EntityDatabaseServer
\@BranchCircuits_Web.Infrastructure.ApplicationInfo.EntityDatabaseCatalog</p>
</div>
</div>
</div>
Does anyone have any idea why these would show up blank when the view renders?
Where is the appropriate place to be able to do something like this only when the application starts?