OnActionExecuting not executing in referenced MVC project
up vote
2
down vote
favorite
I have multiple ASP.NET MVC 5 projects who have headers/menus at the top of the page where the html is exactly the same. There are some menu items, logos, links that get pulled from the database. To eliminate these redundant code across projects, I wanted to use a shared project for just the header, compile and then reference it in each application. I used RazorGenerator.Mvc so my view would be compiled in the DLL and I also use the MvcSiteMapprovider for the menu. So far everything works well. In the shared/referenced project I made a view called "CommonHeader.cshtml" and when I add this partial view to my other MVC projects and compile, it's all good.
I'm having some issue with Sessions, though. In the shared project's controller, I have the following function
protected override void OnActionExecuting
...which calls a sproc and loads some stuff like links/logos into TempData which is then shows in my header eg TempData.Peek("fieldname"). When I run the shared project itself, it loads these TempData fields I put into the View just fine. When I rebuild the other application projects that reference this project, these session/tempdata fields seem to be null. I'm not referencing the session variables from the consuming application views, but from the shared project itself so you would think it would work, but it appears that this OnActionExecuting function doesn't get executed when the code being referenced from another project.
Oddly enough the class that is used by my MvcSiteProvider to build the sitemap/menu will load stuff into Sessions just fine still. So I know I assume the problem ins't that a referenced project can't utilize Session. It just seems like the controller in the referenced project doesn't seem to be running the OnActionExecuting code. Does anyone know why? Or how I can get this to work without having to load all my Session into in that class that loads the SiteMap, keeping it inside the home controller?
c# asp.net-mvc asp.net-mvc-5 session-state
add a comment |
up vote
2
down vote
favorite
I have multiple ASP.NET MVC 5 projects who have headers/menus at the top of the page where the html is exactly the same. There are some menu items, logos, links that get pulled from the database. To eliminate these redundant code across projects, I wanted to use a shared project for just the header, compile and then reference it in each application. I used RazorGenerator.Mvc so my view would be compiled in the DLL and I also use the MvcSiteMapprovider for the menu. So far everything works well. In the shared/referenced project I made a view called "CommonHeader.cshtml" and when I add this partial view to my other MVC projects and compile, it's all good.
I'm having some issue with Sessions, though. In the shared project's controller, I have the following function
protected override void OnActionExecuting
...which calls a sproc and loads some stuff like links/logos into TempData which is then shows in my header eg TempData.Peek("fieldname"). When I run the shared project itself, it loads these TempData fields I put into the View just fine. When I rebuild the other application projects that reference this project, these session/tempdata fields seem to be null. I'm not referencing the session variables from the consuming application views, but from the shared project itself so you would think it would work, but it appears that this OnActionExecuting function doesn't get executed when the code being referenced from another project.
Oddly enough the class that is used by my MvcSiteProvider to build the sitemap/menu will load stuff into Sessions just fine still. So I know I assume the problem ins't that a referenced project can't utilize Session. It just seems like the controller in the referenced project doesn't seem to be running the OnActionExecuting code. Does anyone know why? Or how I can get this to work without having to load all my Session into in that class that loads the SiteMap, keeping it inside the home controller?
c# asp.net-mvc asp.net-mvc-5 session-state
add a comment |
up vote
2
down vote
favorite
up vote
2
down vote
favorite
I have multiple ASP.NET MVC 5 projects who have headers/menus at the top of the page where the html is exactly the same. There are some menu items, logos, links that get pulled from the database. To eliminate these redundant code across projects, I wanted to use a shared project for just the header, compile and then reference it in each application. I used RazorGenerator.Mvc so my view would be compiled in the DLL and I also use the MvcSiteMapprovider for the menu. So far everything works well. In the shared/referenced project I made a view called "CommonHeader.cshtml" and when I add this partial view to my other MVC projects and compile, it's all good.
I'm having some issue with Sessions, though. In the shared project's controller, I have the following function
protected override void OnActionExecuting
...which calls a sproc and loads some stuff like links/logos into TempData which is then shows in my header eg TempData.Peek("fieldname"). When I run the shared project itself, it loads these TempData fields I put into the View just fine. When I rebuild the other application projects that reference this project, these session/tempdata fields seem to be null. I'm not referencing the session variables from the consuming application views, but from the shared project itself so you would think it would work, but it appears that this OnActionExecuting function doesn't get executed when the code being referenced from another project.
Oddly enough the class that is used by my MvcSiteProvider to build the sitemap/menu will load stuff into Sessions just fine still. So I know I assume the problem ins't that a referenced project can't utilize Session. It just seems like the controller in the referenced project doesn't seem to be running the OnActionExecuting code. Does anyone know why? Or how I can get this to work without having to load all my Session into in that class that loads the SiteMap, keeping it inside the home controller?
c# asp.net-mvc asp.net-mvc-5 session-state
I have multiple ASP.NET MVC 5 projects who have headers/menus at the top of the page where the html is exactly the same. There are some menu items, logos, links that get pulled from the database. To eliminate these redundant code across projects, I wanted to use a shared project for just the header, compile and then reference it in each application. I used RazorGenerator.Mvc so my view would be compiled in the DLL and I also use the MvcSiteMapprovider for the menu. So far everything works well. In the shared/referenced project I made a view called "CommonHeader.cshtml" and when I add this partial view to my other MVC projects and compile, it's all good.
I'm having some issue with Sessions, though. In the shared project's controller, I have the following function
protected override void OnActionExecuting
...which calls a sproc and loads some stuff like links/logos into TempData which is then shows in my header eg TempData.Peek("fieldname"). When I run the shared project itself, it loads these TempData fields I put into the View just fine. When I rebuild the other application projects that reference this project, these session/tempdata fields seem to be null. I'm not referencing the session variables from the consuming application views, but from the shared project itself so you would think it would work, but it appears that this OnActionExecuting function doesn't get executed when the code being referenced from another project.
Oddly enough the class that is used by my MvcSiteProvider to build the sitemap/menu will load stuff into Sessions just fine still. So I know I assume the problem ins't that a referenced project can't utilize Session. It just seems like the controller in the referenced project doesn't seem to be running the OnActionExecuting code. Does anyone know why? Or how I can get this to work without having to load all my Session into in that class that loads the SiteMap, keeping it inside the home controller?
c# asp.net-mvc asp.net-mvc-5 session-state
c# asp.net-mvc asp.net-mvc-5 session-state
edited Nov 9 at 21:24
user3559349
asked Nov 9 at 17:27
Brian Lorraine
7318
7318
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
I never did figure this out, but I think I came up with a better way to handle it. I can just create a Model that calls the stored procedure used to get all this information (logo, links, etc) and return this to my header view. Granted, it will get called every single time a page loads, but if it's only a few fields it's not a big deal.
FYI I implemented this and it worked just perfectly. Models... they are your friend: Even if just for meta-related information
– Brian Lorraine
Nov 19 at 16:09
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53230615%2fonactionexecuting-not-executing-in-referenced-mvc-project%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
I never did figure this out, but I think I came up with a better way to handle it. I can just create a Model that calls the stored procedure used to get all this information (logo, links, etc) and return this to my header view. Granted, it will get called every single time a page loads, but if it's only a few fields it's not a big deal.
FYI I implemented this and it worked just perfectly. Models... they are your friend: Even if just for meta-related information
– Brian Lorraine
Nov 19 at 16:09
add a comment |
up vote
0
down vote
I never did figure this out, but I think I came up with a better way to handle it. I can just create a Model that calls the stored procedure used to get all this information (logo, links, etc) and return this to my header view. Granted, it will get called every single time a page loads, but if it's only a few fields it's not a big deal.
FYI I implemented this and it worked just perfectly. Models... they are your friend: Even if just for meta-related information
– Brian Lorraine
Nov 19 at 16:09
add a comment |
up vote
0
down vote
up vote
0
down vote
I never did figure this out, but I think I came up with a better way to handle it. I can just create a Model that calls the stored procedure used to get all this information (logo, links, etc) and return this to my header view. Granted, it will get called every single time a page loads, but if it's only a few fields it's not a big deal.
I never did figure this out, but I think I came up with a better way to handle it. I can just create a Model that calls the stored procedure used to get all this information (logo, links, etc) and return this to my header view. Granted, it will get called every single time a page loads, but if it's only a few fields it's not a big deal.
answered Nov 16 at 15:45
Brian Lorraine
7318
7318
FYI I implemented this and it worked just perfectly. Models... they are your friend: Even if just for meta-related information
– Brian Lorraine
Nov 19 at 16:09
add a comment |
FYI I implemented this and it worked just perfectly. Models... they are your friend: Even if just for meta-related information
– Brian Lorraine
Nov 19 at 16:09
FYI I implemented this and it worked just perfectly. Models... they are your friend: Even if just for meta-related information
– Brian Lorraine
Nov 19 at 16:09
FYI I implemented this and it worked just perfectly. Models... they are your friend: Even if just for meta-related information
– Brian Lorraine
Nov 19 at 16:09
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53230615%2fonactionexecuting-not-executing-in-referenced-mvc-project%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown