<!-- #include virtual="/footer.asp"--> in ASP.NET application
I need to include a header and footer currently located in an asp page. The page takes the language ID and gives you the correct header for the page you are viewing.
I was going thru this: http://foru开发者_StackOverflowms.asp.net/t/1420472.aspx and this particular fragment seemed to explain it better tho I could not wrap my mind around it.
Hi, instead of using include tags, you could compose your page this way: Your .NET application here You can then implement in codebehind remote header and footer download logic and set them in the Literals' Text. After downloading from the remote site, I would suggest to store the header and footer in the application's Cache to avoid too many connections to the remote server. If the same header-and-footer are shared from many pages in your project, moving this structure to a MasterPage could be useful.
Kindly assist.
Well, it would be applicable if header/footer content is coming from some other (remote) server. So the suggested solution is to
- Write code to download header/footer content from remote server
- Cache the content so that you don't have to download it again and again.
- Use literal controls as placeholders on page and set its text to this downloaded content from code-behind.
Now, this may or may not be applicable to your problem. From where does you get the content for header/footer. If its some helper class/method then you can directly call it to set the literal text. You can even do that is master page making things even simpler.
Edit: Additional information requested by OP
You can use WebRequest for downloading content. See this article to get started.: http://www.west-wind.com/presentations/dotnetwebrequest/dotnetwebrequest.htm
Refer below to get started on caching:
http://www.asp.net/general/videos/how-do-i-use-the-aspnet-cache-object-to-cache-application-information
You can use HttpWebRequest to get the required footer text from the asp page and then use the Literal control to display this text.
This page has an example code about how you can submit value to a page and get the response.
精彩评论