My application has some menu buttons that sends the users to my website.
I want to differentiate in the website how many users came from my app, out of all the regular users.
My app is written in C#, and currently I direct users like this:
string url = "http://mysite/somepage";
System.Diagnostics.Process.Start(url);
On the server side, I use Piwik for my web paralytics.
Any suggestions?
Update
One good solution will be to add some parameter to the URL. Yet I was wondering if it's possible to play with the referrer field, for the sake paralytics simplicity.
Add something to the url, probably in the querystring that identifies that the user has originated from your application, like:
string url = "http://mysite/somepage?source=myApplication";
System.Diagnostics.Process.Start(url);
You can/could also use this to track the versions of your app that are in use by adding more to the url, for example ?source=myApplication&version=1.0.3 =)
Just add a parameter to the URL coming from your app, other users will not have that:
string url = "http://mysite/somepage?fromApp=v1";
On your website, you can pick that up to differentiate users. Do a redirect immediately after, so they will not bookmark the page with this URL.
Can't you just add some parameter to the URL your application is using and use that to filter users coming from your app?
Related
I wanna implement url rewriting so that, for example, all german pages have a url with /de/ after the domain name (and english pages with an /en/) but I don't actually have to create and manage all those subdirectories. I want this "de"/en to persist through out the website
Just like mentioned in the article below:-
http://www.deevelop.com/en/web-design-company/blog/12/Multilingual-website.html
Please check the content under "SUBDIRECTORIES" heading in this article.
This article doesn't explain stuff in detail. Can I please have link to more such examples that are elaborative enough?
Or if someone has implemented such a thing may help. Thanks
URL rewriting is the process of intercepting an incoming Web request and redirecting the request to a different resource. When performing URL rewriting, typically the URL being requested is checked and, based on its value, the request is redirected to a different URL. For example, in the case where a website restructuring caused all of the Web pages in the /people/ directory to be moved to a /info/employees/ directory, you would want to use URL rewriting to check if a Web request was intended for a file in the /people/ directory. If the request was for a file in the /people/ directory, you'd want to automatically redirect the request to the same file, but in the /info/employees/ directory instead.
You first need to download SP1(free) and install it, then follow these links:
http://msdn.microsoft.com/en-us/magazine/2009.01.extremeaspnet.aspx
http://chriscavanagh.wordpress.com/2008/03/11/aspnet-routing-goodbye-url-rewriting/
I have an iFrame Facebook application. I am using the Facebook C# SDK, Facebook and Facebook.Web libraries.
When a user first comes to my application I create a FacebookApp object on page_load(). If the app.Session is null I create a CavasAuthorizer(app) then call Authorize().
Two problems:
First, the redirect URL that is generated by calling Authorize causes Facebook to error with a bad "next" parameter. Says the "next" parameter is not owned by the application. It looks like this:
next=http://localhost:4002/facebookredirect.axd/mygame_dev/mygame.aspx
I can edit the code in CanvasURLBuilder to make the next look like this:
next=http://localhost:4002/mygame.aspx
At this point the URL works if I cut and paste into a browser however it brings me to my second issue.
When the code runs the user is presented with a mostly empty page with a mid-sized Facebook image and a link "go to Facebook". When the user clicks on the link it then takes the user to the correct authorization page for my application.
I have a feeling these are two possibly related issues but potentially separate.
Any help here would be greatly appreciated.
-Andy
For the first problem
Make sure the site Url in the app configuration page is set to http://apps.facebook.com/[your_app]/
For the second problem.
When you are not authorized you are redirected to the login url but you can't do it from your iframe since it will redirect the iframe and you will get a Facebook inside facebook.
You should use window.top.location = ... to redirect the parent window.
EDIT
Facebook C# SDK Already does this for you when using the Mvc part of the SDK. Since you are using webforms you should use this code that is the equivalent.
protected void Page_Load(object sender, EventArgs e)
{
var fb = new FacebookApp();
var auth = new CanvasAuthorizer(fb);
if (!auth.IsAuthorized())
{
var url = auth.GetLoginUrl(new HttpRequestWrapper(Request));
var content = CanvasUrlBuilder.GetCanvasRedirectHtml(url);
Response.ContentType = "text/html";
Response.Write(content);
Response.End();
return;
}
//...Go on if authorized
}
To test locally make sure your Site URL and Canvas URL in facebook is something like http://localhost:8181/yourpage. Then make sure in VS you set the setting under project properties\Web so that ports are not dynamically generated and you can use 8181 (or whatever port you like, as long as it is the same as in FB).
I think your Callback url in your web config is pointing to localhost. You can't do that since the code actually runs inside of Facebooks IFrame. Localhost is localhost to the facebook web server. You will have to give a valid url in the Callback key in your web.config. If you don't have a domain you can map to your ip then check out any of the free dynamic dns clients out there. No-ip is one exammple (and one I use personally).
Please consider the following scenario,
There are two web applications App1 & App2. A user would submit his information on App1 though a form. On click of a specific button/link on App1, the same data should be posted to a page on App2 and the user should also be redirected to the same page on App2.
I would like some help in finding out the best way to implement this functionality.
One of the approaches that I have already tried out is by creating a temporary HTML form at runtime, setting the action attribute of the form to the App2 Page and get the form posted by using javascript submit. The data can then be fetched on App2 page by using the response.form object.
This approach works well, but i was still wondering if there is any other way to implement the required functionality.
I would really appriciate if you can give some insights on using RESTful webservices to implement this, or else, using some HttpModule to intercept requests at App1 and modify redirect response to app2 or any other approach that you might find fit for the purpose.
Edit:
Using querystring isnt an option for me.
I've had a need to do similar things with feed agregation and building rss feeds from web page content on different domains.
User Gets app1 page, fills in details and submits then on the server for app1 I have a method that looks like this ...
HTMLDocument FetchURL( string url )
{
WebClient wc = new WebClient();
string remoteContent = wc.DownloadString(url);
// mshtml api is very weird but lets just say you have to do things this way ...
HtmlDocument doc = new HTMLDocument();
IHTMLDocument2 doc2 = (IHTMLDocument2)doc;
doc2.write(new object[] { remoteContent });
return (HTMLDocument)doc2;
}
This function does 2 things of use ...
It gets the page of content at "url"
It parses that content in to a HTMLDocument object
Once you have this function you can then call it passing it the url to the remote page and get back a html doucment.
The functions in the HTMLDocument object will allow you to do javascript like dom queries such as :
docObject.GetElementById("id");
I then have different functions that do different things with this object based on the page / site i'm returning data from.
There is however one fatal flaw here ...
This is likely to work really well with sites that don't change much in structure and are built by code but not so well on less dynamic sites.
With stackoverflow for example its easy to pull out a question and the accepted answer for that question so I could use this code to pull and publish content from here on my own web site.
However ...
This is not going to help you for user / login related details as this sort of information is not shared to generally everyone.
It's bit like me going and trying this to link facebook profiles to my own website, I would have to go through some form of api that asked the user to authenticate their details before making the request.
simply pulling a web page based on a url only will give the other site no authentication information unless that site accepts the user login details in the quesrystring and you already have them.
You may however be able to chain requests by ripping apart my sample method, requesting the login page parsing the results, filling in the form, then posting back using the same web client instance to login then requesting the url.
The idea being that you would have a form that asks the user to put in their login details for the remote site on your site then you go and find their profile page based on that.
This would be best farmed out to a class rather than just a simple method like i have here.
In my case though i was only after something simple (the bbc top 40 uk charts) which i pulled information from not only the bbc but places like amazon, google, and youtube, then i built a page :)
It's neat but serves no functional purpose other than pulling all your other fave sources of info on to 1 page.
If you are already committed to using javascript, then why not an ajax post, and change the window.location based on the response?
You can use HttpServerUtility.Transfer this will preserve your form contents and transfer the user to the new page.
http://msdn.microsoft.com/en-us/library/system.web.httpserverutility.transfer.aspx
I have built something like what you are describing, and I found that using a <form> tag to POST to app2 is the most reliable way... basically, the way you found that worked well.
If App2 is residing on a different domain, it's usually best to create your own interface for the submission, and have that interface handle the posting from App1 to App2.
(Browser) -> Submits form to App1 ->
(App1) -> validate input
-> stores local info
-> creates an HttpRequest/POST object
-> posts to App2
(App2) -> handles the post
<- returns the response
-> confirms the results of App2
<- returns the results to the browser.
In essense, you want to control and proxy requests from your Applications domain to any outside interfaces as much as possible.
Note: I'm answering my own question
just to have a correct answers marked
against it. All the suggestions
provided by various members here are
correct in their own way, but they
were not apt for my requirements.
Hence, I cant accept any of them as
correct.
The way I have Implemented is by creating a custom control which would have a configurable property containing the URL to post data and another one accepting a dictionary object as the data input to be posted.
This control would internally create a HTML form with action attribute set to the URL specified by the user and have the data feilds created out of the dictionary object. This form would then be posted on the button click event on the page hosting this control.
I have a situation in which there is a login page.After successfully logging in,i 'm redirected to http:\localhost\default.aspx.I want that after logging in my browser url should look like www.abc.com but the pa ge opened would be http:\localhost\default.aspx.I'm not able to do this using URL rewriting
Unfortunately, this is not possible for internet users - you can't 'fake' the URL that your user is looking at. Otherwise evil-doers could re-write 'www.istealyourmoney.com' as 'www.trustworthybank.com', etc.
The only possible option I can think of is if your users are all on the same local area network. In that case, you can add an entry to your HOSTS file with www.abc.com aliased to 'localhost'.
As said by JBRWilkinson this is not generally possible, however if you want to do this just to help you build out a site while you work on it locally, add an entry to your HOSTS file (on Windows: C:\Windows\System32\Drivers\Etc\Hosts) that maps www.abc.com to 127.0.0.1. You want to add a line that looks like this to the end of the file:
127.0.0.1 www.abc.com
Then you can access your local development website with the URL www.abc.com. Note that this will also block access to the live version of that website on your machine.
can't we achieve using IIS url rewrite?
http://www.codinghorror.com/blog/archives/000797.html
I am developing an application in which I am displaying products in a grid. In the grid there is a column which have a disable/enable icon and on click of that icon I am firing a request through AJAX to my page manageProduct.aspx for enabling/disabling that particular product.
In my ajax request I am passing productID as parameter, so the final ajax query is as
http://example.com/manageProduct.aspx?id=234
Now, if someone (professional hacker or web developer) can get this URL (which is easy to get from my javascript files), then he can make a script which will run as a loop and will disable all my products.
So, I want to know that is there any mechanism, technique or method using which if someone tries to execute that page directly then, it will return an error (a proper message "You're not authorized or something") else if the page is executed from the desired page, like where I am displaying product list, then it will ecxecute properly.
Basically I wnat to secure my AJAX requests, so taht no one can directly execute them.
In PHP:
In php my colleague secure this PHP pages by checking the refrer of the page. as below:
$back_link = $_SERVER['HTTP_REFERER'];
if ($back_link =='')
{
echo 'You are not authorized to execute this page';
}
else
{
//coding
}
Please tell me how to the same or any other different but secure techique in ASP.NET (C#), I am using jQUERY in my app for making ajax requests.
Thanks
Forget about using the referer - it is trivial to forge. There is no way to reliably tell if a request is being made directly or as a response to something else.
If you want to stop unauthorised people from having an effect on the system by requesting a URL, then you need something smarter then that to determine their authorisation level (probably a password system implemented with HTTP Basic Auth or Cookies).
Whatever you do, don't rely on http headers like 'HTTP_REFERER', as they can be easily spoofed.
You need to check in your service that your user is logged in. Writing a good secure login system isn't easy either but that is what you need to do, or use the built in "forms authentication".
Also, do not use sequential product id's, use uniqueidentifiers, you can still have an integer product id for display but for all other uses like the one you describe you will want to use the product uniqueidentifier/guid.