简体   繁体   中英

Dynamic Page Rendering in ASPX

I'm very new to C# and .NET and I find myself faced with a problem and I'm not sure in which direction I need to head.

My company works with a third party subscription fulfillment system for many functions, including billing and renewals. This system has the capability of automatically sending an email when certain events are triggered. For example, each subscription goes through, what we call, a renewal series. This series consists of several efforts spread accross the life of the subscription.

When a subscription qualifies for a certain effort of this series, we can have an event generated that will cause the system to send a HTTP POST request to a given URI with an XML payload. The endpoint (an .aspx page) receives the request, processes it, and returns a response with, in this case, HTML code. That HTML is then emailed out by the fulfillment system.

I have a basic web application created with a few of these .aspx pages up and running. Each page has a corresponding .cs code behind file.

Here's where my question really starts. In our fulfillment system, we can only define one endpoint per combination of event and product. So, no matter which effort a subscription is qualifying for at the time, the event itself is the same. What is different, though, is the XML of the HTTP POST request. It's in that XML that I can tell for which effort the request has been generated. The reason that is important is because the HTML of the corresponding email is different for each effort. To phrase it a slightly different way, the HTML that should be rendered is different, top to bottom, for effort 1 than effort 2. Effort 2 is different than effort 3, and so on.

So, what I'm trying to figure out is how to "direct the traffic". Since all of these requests will come to a single endpoint, I need to dynamically return the correct HTML for the corresponding effort.

In a different .aspx page in this same app, there is some content that needs to be generated dynamically depending on the contents of the request. In that case, I used two PlaceHolder controls, one for each possible set of text. Then, in the code behind, set their Visible property to true or false as needed.

I dismissed the idea of doing that in this case early on since there are five or six HTML templates and stuffing all of them into one page would be messy and hard to maintain.

This is where I'm at the point that I don't know what to do next. I have a feeling that a User Control or Custom Control is going to be the way to go? But, is plain old redirection a better option? Or none of the above?

The solution you dismissed is very close to the correct one. However, there is something you can do to simplify it and make maintenance easier.

What we want to do here is build a custom control or a user control for each effort. This will let you maintain the code for the efforts separately, without mixing everything together in one place. Then your entire endpoint *.aspx page consists of a single placeholder control. When processing a request, your Page_Load method will parse your xml and figure out what kind of effort you need. It will then create a new instance of the proper control, add it to the placeholder, and pass the rest of the data to the control to finish processing.

Because there is some commonality among all the controls here (the ability to receive an xml message), you may first want to also create one base control for the individual effort controls to inherit.

From what I understand, you'd like to have a single endpoint but still be able to "route" requests internally. This is easily possible.

You could for example transfer requests internally, using Server.Transfer . This way you can have your 5 or 6 different HTML templates and then route incoming requests to a correct template depending on the content of the request.

enter link description here

Here we give An Example here to creating a new .aspx page at run time. We also give the option to give page name. The user can give as he/she like. Like Google blogging we make new page at runtime.The new page is not in the website, this page create needs to be created at runtime and needs to be dynamic.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM