Global routing parameter in ASP.NET MVC - asp.net

When a user clicks on a link, I want to log some information. I can't do an AJAX request because if they clicked on a link, the page will unload (since they're going to a new page), and I don't want to force them to stay on the page until a synchronous event finishes.
So one idea I had was to add a parameter to the url. I.e. the urls would be actual/action?actualParams&infoIWantToLog=data. Then I could strip off the info I want to log, log that, and then pass off their URL to the action which they actually wanted to go to. Is this possible to do with MVC routing?

Typically tracking URLs send the user to a specific page (or action, in this case), say, /Track, and then pass the parameters to log (including the URL to send the user to) through the querystring.
For instance, go to Google and search on a term. Right click on a result and copy the URL. Now paste it into Notepad. You'll see that it's not a direct link to the search result, but rather to a Google tracking page. For instance, when I search for asp.net and click on the first result (for www.asp.net), this is the actual URL Google sends me to:
http://www.google.com/url?sa=t&source=web&cd=2&ved=0CDcQFjAB&url=http%3A%2F%2Fwww.asp.net%2Fget-started&rct=j&q=asp.net&ei=BauTTIuCDIaWsgOHgo3ACg&usg=AFQjCNGR6cOBKtUWIKZs9jnpz0vYRDu_EA&sig2=r2q31zniuxHQ4Y6BIoudow&cad=rja
That page logs my click and then redirects me to the www.asp.net website.
Your Track action would do the same thing. You'd create a Track controller with an Index action and then in there you'd parse the querystring, log the information, and then return a RedirectResult to the URL you want to send the user.
Make sense?

Related

How can I programmatically log into an ASP.NET website that uses Forms authentication?

I'm trying to automate testing of an ASP.NET (not MVC) website that uses Forms authentication.
I want to simulate what happens when a user submits a particular form; to do this, my code can POST to the corresponding URL - but that won't work unless my code can first log in as my test user.
I've tried posting to the LogOn page (supplying a suitable username and password), but this fails - and I think it fails because the website uses ASP.NET event validation. (If I use Fiddler to watch what's sent to and from the browser, there's an __EVENTVALIDATION hidden form item).
I'm guessing that I'll need to visit the login page once, get the __EVENTVALIDATION value, and include that when I post the username and password to the LogOn page?
Is that all I need to do, or is spoofing a Forms-authentication-based website a non-starter?
Well, in case it helps anyone else, I was able to get this working by issuing a GET request to the LogOn page, extracting the values of the __EVENTVALIDATION, __VIEWSTATE and __VIEWSTATEENCRYPTED hidden form fields from the returned HTML, and then POSTing those values back to the LogOn page along with the rest of my form values (user name and password).
I'm using a single instance of HttpClient throughout, so the ASP.NET session cookie is preserved between requests.

Why isn't my LinkedIn API authorization method working?

I'm following the authorization instructions but I can't figure out how it's supposed to work. I'm sending a request to https://www.linkedin.com/uas/oauth2/authorization, and passing the required fields. The call succeeds and returns some authorization html, which I display, and it looks like this:
But the form containing the Allow Access button has an action of /uas/oauth2/authorizedialog/submit, and so clicking it fails, because there's no domain specified. Clearly it's supposed to be displaying some sort of authorization on the LinkedIn site, not my own. What am I doing wrong?
Argh, what I was doing wrong was trying to download the contents of the authorization url page, instead of simply redirecting to it. Redirecting to it does open the page on their site, and I can authorize, and then be redirected back to my own callback.

Google Analytics URL for event tracking

I'm tracking several pages with Google Analytics. Each page uses a custom URL passed to _trackPageView:
_gaq.push(['_trackPageview','/someurl']);
(Our site uses the same URL on every page, so I'm stuck with using a virtual URL to identify every page).
This all works fine, but I'm noticing that the virtual URL isn't being associated with any events I later track on the same pages. The events are recorded just fine, but if I view the Events->Pages section in the standard reports, the page URL shown is the main URL for the site, not my virtual URL. So in my case every event ends up being associated with the same URL for the site, instead of the '/someurl' defined earlier.
I'm not doing anything special with the event tracking code, just the usual _gaq.push( [ "_trackEvent", ... ] );
I have a few user timings, and they are showing the same behaviour.
Does anyone know if I can specify a virtual URL to send along with a event?
Apologies if you've already considered this, but how about you add the virtual url to the event label and distinguish between events on different pages that way?

Track Keywords from Google Adwords and GA and store them

I run an adword campaign on google.
Users type in keywords and come to my landing pages via few ad's they see. Now my landing page has some 2 pages. One has informational which brings a user directly to the landing page after ad click - second is a signup form. Now I wish to capture the keywords he has typed in and then come into this form so that we know how users are reacting to our ads and what do they type to get to us.
The complex part is how can we use the GA - API to track this down. Since user will landing on /page and may signup finally from /page1 so we need to store those kewyords from his url (which is done via the Value Track codes in the url) and then store in the cookies so that when he later comes to /page1 and is signing up the same keywords can be passed and stored in the backed?
Is this possible and some can please help with this - where to look for how to accomplish this.
Thanks
I append a code to my ad's URL in AdWords:
www.example.com/?code=some-unique-id
On the landing page I check for the query string parameter, and if found store it in a cookie.
Any subsequent pages can access the cookie, and get the code from the original landing page.
This is only ad-group level, but it's a start.

Need help on HttpWebrequest

HI Guys I have the same issue and I am looking to solve it. Here is detail I have two web sites WebsiteA and WebSiteB (WebsiteB is not in my control, A type of black box for me.).
Both websites have seprate login page
I have alist of users,password of websiteB which I stored in database.
I want a kind of common login page. If user is login to websiteA and he want to go to websiteB, he dont have to enter the login and password information again.
I can not touch the code of websiteB. it's alredy deployed and runing.
In websiteB in login form they have a Userid textbox and Password textbox and and a login Button. This butoon is not a submit button. It has a click event which calls a function to validate the user. it's not a simple post.
WebsiteB has one webpage which has different frames. After login sucessfull. The pages doesnt go to any other page it remain on the same page but load the different frame.
According to my knowledge. I can use httpwebrequest class. But faceing the following problem.
Can not click the button.
Response.Redirect does not work.
It seems that WebsiteB is not storing any thing in cookies as cookies always return me a empty string
I really appriciate if anyone can help me on it.
How Can I use response.Redirect . As when I redirect it shows me the same login page.
Without knowing how login works to site B I could not say for sure, but at some point, I'm sure there is a post with login information. My best guess at a solution would be try to imitate what site B does on login. Use firebug and watch what gets sent, and what is returned. You'll have to mimic this behavior.
It may be something like:
POST credentials to site B for verification, returns verification result.
If verification is good, use token from verification result to redirect to site B.
Again, without knowledge of site B, I could not say, but whatever it does, it likely does using normal http, thus you can probably duplicate it. That said, site B may forbid you from logging in by only accepting logins from certain URLs.
As for using the HttpWebRequest, I think you'll find you're better off just having a hidden form which you submit from site A.
A HttpWebRequest will execute on the server of WebsiteA. Even if you execute the correct HttpWebRequest POST to WebsiteB, you won't be able to pass that session cookie to the user's browser without also immediately redirecting to WebsiteB.
There are other single-sign-on techniques you may want to investigate - the approach you have described will not work.
HI I figure out . We can create a string of XML and the converting the string into bytes and then use the normal write function of HttpWebrequest to Write the XML.

Resources