Last post Jul 27, 2007 02:25 AM by mickyjtwin
Jul 17, 2007 07:39 PM|mickyjtwin|LINK
I am working on a large project, and am quite new to HttpModules/HttpHandlers. The basic site structure is as follows:
The site can have multiple views, and there are many categories.
Would I be right in saying I could use regex for the latter part, i.e. after the category/
How would I go about iterating though that? With if statements?
Once I have the page that is being requested, I need to load those specific modules into the page.
Also, I need to capture 404 page errors. Is there any tutorials anyone knows of handling this?
Jul 18, 2007 11:04 PM|Rex Lin - MSFT|LINK
I believe you cannot assign the particular modules into some of the pages. When an instance of
HttpApplication is created, any configured modules are also created. For instance, if the application is configured to do so, ASP.NET creates a
SessionStateModule module. After all configured modules are created, the
HttpApplication class's Init method is called. Here is a Good resource:
Second: ASP.NET provides a simple yet powerful way to deal with errors that occur in your web applications. We will look at several ways to trap errors and display friendly meaningful messages to users. We will then take the discussion a step further and
learn how to be instantly notified about problems so you can cope with them right away. As a geek touch we will also track the path 404's travel.
If i misunderstand you about your question, please feel free to correct me and i will try to help you with more information.
I hope the above information will be helpful. If you have any issues or concerns, please let me know. It's my pleasure to be
This response contains a reference to a third party World Wide Web site. Microsoft is providing this information as a
convenience to you. Microsoft does not control these sites and has not tested any software or information found on these
sites; therefore, Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or
information found there. There are inherent dangers in the use of any software found on the Internet, and Microsoft cautions
you to make sure that you completely understand the risk before retrieving any software from the Internet.
Jul 19, 2007 12:21 AM|mickyjtwin|LINK
Leaving the 404's aside for the moment, i want to further discuss iterating through the url as I need...
using the following example, I'm trying to figure out the best way to work through the url.
Basically I need to do the following, and if you have an easier solution, please comment...
check the first part of the url, i.e. someview || somepage.aspx
Grab that string, and try and load it as a view. If it loads as a view, then set that view into the context. If it is a page, then load the page object, and set that into the context.
What if there is more than just the view? i.e. /someview/somepage.aspx || /someview/somesection/somepage.aspx || /someview/somesection.aspx
Grab that string, and try to load it as a section. If it loads, set that into the context. Again, we might have more than a section and go into a page after that. Try and load, and set in context.
Is this making sense?
I thought if I using this..
int segmentLength = _app.Context.Request.Url.Segments.Length;
string segments = _app.Context.Request.Url.Segments;
if (segmentLength >= 2)
for (int i = 1; i <= segmentLength - 1; i++)
if (i < segmentLength - 1)
ProcessSegment(segments[i], false); //false means that there isn't another segment
ProcessSegment(segments[i], true); //true means that there is another segment
Jul 22, 2007 06:32 PM|mickyjtwin|LINK
In my OnBeginRequest, I am getting the URL, and depending on what type of module it is, either a view, section, blog article, it will load that module value into the Context Item. However, what I want to do now, is before I load this in, see if the user
is authorized to view that section, if they are, load, if not, redirect to login page etc.
Can I do this in there? I know I can load Membership, but can I do it already in OnBeginRequest? If I can't what would be the best process to do this in?
Jul 27, 2007 02:25 AM|mickyjtwin|LINK
Ok, I've been trying to figure this one out, but am hitting my head up against a brick wall!!
Every time I try and explain it, I confuse myself more, so I'll try and get it right...
Even though I'm writing a urlrewriter, I have no issue with this, it's the actual coding logic of how to process certain segments. i.e.
I have a url, which I split into segments which returns the following:
array = /
array = view/
array = section/
array = somepage.aspx
array = /
array = somepage.aspx
array = /
array = view.aspx
***NOTE, the array is returned from Url.GetSegments(); This might be my first issue, I should just split it up myself??
To continue. I now need to iternate through the array, and process each segment(which will ultimately load the page being requested).
Firstly, I need to try and load a view from the first segment. If it didn't find one, I will automatically load a default view, but then I need to check that same segment to see if a section exists. If it doesn't, then I need to check if I can load it as a
regular page. If I can't do that, then I return an error. It it does load as a page, then set that into the context items, and rewrite the path.
Ok, so now, lets continue by saying that if I did find a view, AND there is another array segment, I need to then try and load that next segment as a section. We have now loaded successfully a section. If there are no more segments, then the user is trying
to view the section homepage. If there is another segment, then lets try and load that as a blogtype. Let's say we didn't find a blogtype, then lets try and load it as a page, etc (error or show page)
Let's say we DID find a blogtype, if there isn't another segment, then the user wants the blogtype homepage. If there is another segment, then try and load it as a blog title. Again, if we find one, and no more segments, then user wants that blog title homepage.
If more segments, try and load it as a blog entry title. Same deal.
Is this making any sense to anyone? I'm having issues with the logic of stepping through it all. To do it as if statements would be quite large.
I started by creating a method
bool ProcessSegment(string segment, string type)
bool LoadSection(string segment)
//try and load section, if found return true, else return false
*** same for LoadView, LoadPage, LoadBlogType etc.
So I'm basically returning a boolean if the process segment worked. But I'm not sure how to tie that in with appropriate if statements, or then checking if there is another array segment??????
I am not sure how to implement a solutiong as valenumr write above.
I really need a solutiong to this. Thanks for help in advance,