I have been browsing the forum to look for a way to open a WebPage from the app.HandleURL event. Maybe I have not been looking good enough, but can’t find any help so far.
What I try to do is creating a link I can use in emails. When clicked it will open the WebApp at the right location.
These locations (pages) are dynamic. I need to be able to pass tokens and other data as well.
A token I generate is time sensitive. On the server side I decide if a token is still valid. This way I can send out a link that can only be used once, or expires after a specific amount of minutes. The link also provides the name of the page.
Link Examples:
www.mydomain.com/resetpassword?token=1234567890
www.mydomain.com/contact?token=1234567890
In the HandleURL I can retrieve the data like “resetpassword” and “contact” as path data
dim path as string = Request.Path
The parameters are retrieved by doing this:
dim token as string = Request.GetParameter("token")
I then use Select case path to find what the link pointed to and open the right page.
But I got an error that the session is not available at the point of dealing with the HandleURL event.
// We need to find the session for the given SessionID. For security
// reasons, always lookup the session with the Request.RemoteAddress
// value. Passing the address as part of the request in any way would
// pose a security risk to your end user.
// We will create a WebSessionContext object to put this session in
// context, causing our Session object to become value.
Dim SessionContext As New WebSessionContext(Self.SessionWithIdentifier(SessionID,Request.RemoteAddress))
Okay… I just don’t exactly know where I have to deal with the WebSessionContext.
I just want to place a link in an email I will send. This link will then direct the user to the right place in the WebApp. This way the user will never have to browse to find that place where he/she needs to go to.
[quote=240056:@Albin Kiland]Could it be that you are using HandleURL and I thought you were talking about HandleSpecialURL?
My mistake, sorry for all the fuss :)[/quote]
No problem… I am very forgiving this time of year
I tried to avoid HandleSpecialURL to make the links easier. I will try to create links I will post in my emails like this
www.domain.nl/api/EditProfile?token=0123456789
Not sure if that works though. I have no clue if a session is in scope at all, at that point.
But what if I just want to show a certain page of my app. The app will always open with then “DefaultWebPage”, right?
My workaround is having the DefaultWebPage deal with the redirecting part. But that seems much slower, since the browser has to open the DefaultWebPage first, and then the page I actually want to go to
[quote=240062:@Edwin van den Akker]But what if I just want to show a certain page of my app. The app will always open with then “DefaultWebPage”, right?
My workaround is having the DefaultWebPage deal with the redirecting part. But that seems much slower, since the browser has to open the DefaultWebPage first, and then the page I actually want to go to[/quote]
[quote=240044:@Albin Kiland]Basically you’ll need this:
(Snippet from the LR)
// We need to find the session for the given SessionID. For security
// reasons, always lookup the session with the Request.RemoteAddress
// value. Passing the address as part of the request in any way would
// pose a security risk to your end user.
// We will create a WebSessionContext object to put this session in
// context, causing our Session object to become value.
Dim SessionContext As New WebSessionContext(Self.SessionWithIdentifier(SessionID,Request.RemoteAddress))
[/quote]
That may not work starting in 2015r4. To fix the problem with users moving from network to network, the remote address is no longer considered a constant.
The reason why is because I want to create nice and clean links. In Handle URL those links are very easy to intercept. But obviously not too easy to make them redirect. I have even been looking at URL rewrite methods inside a web.config file, to get a nice looking link, rewrite the URL inside the web.config file to a base link with the different path parts as querystring parameters.
I was actually planning on looking at that this week. But regular work is kind of in the way. So, I have to deal with my “problem” after hours
If you want to redirect, you could push some parameters into a global dictionary, perhaps using a cookie to temporarily identify the browser and then set the Location header and return a status of 304 in the HandleUrl event. When the Session starts, retrieve the cookie and go look up the data that you stored. The only issue is that you’d have to manually write the cookie info.
The browser will only send the cookie back to the exact same domain, but as long as it’s on the same server, that shouldn’t be a problem. As it has no expiration date, the browser should delete it as soon as it is quit.