[RESOLVED]Variable in _AppStart

Hey guys,

I want to set a global variable – to reduce the amount of code throughout my application.

I have created _AppStart.cshtml and put this in the root with this:

@{
    var test_email = "test@test.com";
}

As a result, I should be able to to type @test_email on any page within my application and it should render test@test.com but I just get an error saying that The name ‘test_email’ does not exist in the current context.

Not having much luck and I followed the information here: http://www.asp.net/web-pages/overview/ui,-layouts,-and-themes/18-customizing-site-wide-behavior

Any help is appreciated :)

Hello,

In the _AppStart:

AppState["test_email"] = "test@test.com";

In the page:

@AppState["test_email"]

Good Luck..

ayanmesut

Hello,

In the _AppStart:

AppState["test_email"] = "test@test.com";

In the page:

@AppState["test_email"]

Good Luck..

Worked perfectly! Thank you very much!!

Leave a Reply