How to send a Facebook App request/ invite? (MVC4)
At the moment I am creating a MVC4 web application and use the Facebook API.
I implemented this method to send a app request, but I get this error
"(GraphMethodException - #100) Unsupported post request.". How to solve
this problem?
public void SendAppRequest(string facebookUserId, string message)
{
FacebookClient fbClient = new FacebookClient();
fbClient.AccessToken = getAccessToken();
dynamic nparams = new ExpandoObject();
nparams.message = message;
nparams.title = "To receive notify messages of the Project Web
application, accept this request.";
var response = fbClient.Post(facebookUserId + "/apprequests",
nparams);
}
Thursday, 3 October 2013
Wednesday, 2 October 2013
How do you overload MVC Controllers to avoid repeating common code?
How do you overload MVC Controllers to avoid repeating common code?
I'm working on a new MVC 5 project. It's a single multi tenanted site that
allows many organisations and branches to maintain a page. All pages start
with the following url format:
http://mysite.com/{organisation}/{branch}/...
For example:
http://mysite.com/contours/albany/...
http://mysite.com/contours/birkenhead/...
http://mysite.com/lifestyle/auckland/...
I've declared my RouteConfig with the {organisation} and {branch} before
the {controller} and {action}:
routes.MapRoute(
name: "Default",
url: "{organisation}/{branch}/{controller}/{action}/{id}",
defaults: new { controller = "TimeTable",
action = "Index",
id = UrlParameter.Optional });
This is working just fine. However EVERY single controller now has
identical code in the top of it that examines the organisation and branch.
public ActionResult Index(string organisation, string branch, string name,
int id)
{
// ensure the organisation and branch are valid
var branchInst = _branchRepository.GetBranchByUrlPath(organisation,
branch);
if (branchInst == null)
{
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
}
// start the real code here...
}
I'm keen on the DRY principle (Don't Repeat Yourself) and I'm wondering if
it's possible to somehow isolate that common code and change my controller
signatures to something like this:
public ActionResult Index(Branch branch, string name, int id)
{
// start the real code here...
}
I'm working on a new MVC 5 project. It's a single multi tenanted site that
allows many organisations and branches to maintain a page. All pages start
with the following url format:
http://mysite.com/{organisation}/{branch}/...
For example:
http://mysite.com/contours/albany/...
http://mysite.com/contours/birkenhead/...
http://mysite.com/lifestyle/auckland/...
I've declared my RouteConfig with the {organisation} and {branch} before
the {controller} and {action}:
routes.MapRoute(
name: "Default",
url: "{organisation}/{branch}/{controller}/{action}/{id}",
defaults: new { controller = "TimeTable",
action = "Index",
id = UrlParameter.Optional });
This is working just fine. However EVERY single controller now has
identical code in the top of it that examines the organisation and branch.
public ActionResult Index(string organisation, string branch, string name,
int id)
{
// ensure the organisation and branch are valid
var branchInst = _branchRepository.GetBranchByUrlPath(organisation,
branch);
if (branchInst == null)
{
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
}
// start the real code here...
}
I'm keen on the DRY principle (Don't Repeat Yourself) and I'm wondering if
it's possible to somehow isolate that common code and change my controller
signatures to something like this:
public ActionResult Index(Branch branch, string name, int id)
{
// start the real code here...
}
I am getting .asmx file not found exception
I am getting .asmx file not found exception
Apparently there is some iis configuration issue. I am getting the the error
System.ServiceModel.EndpointNotFoundException : There was no endpoint
listening at http.....asmx that could accept the message. This is often
caused by an incorrect address or SOAP action. See InnerException, if
present, for more details. ---- System.Net.WebException : The remote
server returned an error: (404) Not Found.
What should I do? I don't know anything about iis. I am just testing some
application
Apparently there is some iis configuration issue. I am getting the the error
System.ServiceModel.EndpointNotFoundException : There was no endpoint
listening at http.....asmx that could accept the message. This is often
caused by an incorrect address or SOAP action. See InnerException, if
present, for more details. ---- System.Net.WebException : The remote
server returned an error: (404) Not Found.
What should I do? I don't know anything about iis. I am just testing some
application
Insert table column value in the Php Session
Insert table column value in the Php Session
Hello, in my mysql database I have table called users which has primary
key column called userID which is Auto Increment column. I would like to
get inside the session array the value of this column for the logged in
user, here is how the array looks like right now:
array(4) { ["loggedIn"]=> bool(true) ["username"]=> string(9) "user"
["password"]=> string(3) "123" ["userID"]=> NULL }
This is the code of my login form:
session_start();
$usr = new Users;
$usr->storeFormValues( $_POST );
if( $usr->userLogin() ) {
header( 'Location: cursos.php' ) ;
$_SESSION["loggedIn"] = true;
$_SESSION['username'] = $_POST['username'];
$_SESSION['password'] = $_POST['password'];
$_SESSION['userID'] = $_POST['userID'];
and this is my login function:
public function userLogin() {
$success = false;
try{
$con = new PDO( DB_DSN, DB_USERNAME, DB_PASSWORD );
$con->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
$sql = "SELECT * FROM users WHERE username = :username AND password =
:password LIMIT 1";
$stmt = $con->prepare( $sql );
$stmt->bindValue( "username", $this->username, PDO::PARAM_STR );
$stmt->bindValue( "password", hash("sha256", $this->password .
$this->salt), PDO::PARAM_STR );
$stmt->execute();
$valid = $stmt->fetchColumn();
if( $valid ) {
$success = true;
}
$con = null;
return $success;
How this can be acheived ? If anyone can help I would appreciate it. Thank
you.
Hello, in my mysql database I have table called users which has primary
key column called userID which is Auto Increment column. I would like to
get inside the session array the value of this column for the logged in
user, here is how the array looks like right now:
array(4) { ["loggedIn"]=> bool(true) ["username"]=> string(9) "user"
["password"]=> string(3) "123" ["userID"]=> NULL }
This is the code of my login form:
session_start();
$usr = new Users;
$usr->storeFormValues( $_POST );
if( $usr->userLogin() ) {
header( 'Location: cursos.php' ) ;
$_SESSION["loggedIn"] = true;
$_SESSION['username'] = $_POST['username'];
$_SESSION['password'] = $_POST['password'];
$_SESSION['userID'] = $_POST['userID'];
and this is my login function:
public function userLogin() {
$success = false;
try{
$con = new PDO( DB_DSN, DB_USERNAME, DB_PASSWORD );
$con->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
$sql = "SELECT * FROM users WHERE username = :username AND password =
:password LIMIT 1";
$stmt = $con->prepare( $sql );
$stmt->bindValue( "username", $this->username, PDO::PARAM_STR );
$stmt->bindValue( "password", hash("sha256", $this->password .
$this->salt), PDO::PARAM_STR );
$stmt->execute();
$valid = $stmt->fetchColumn();
if( $valid ) {
$success = true;
}
$con = null;
return $success;
How this can be acheived ? If anyone can help I would appreciate it. Thank
you.
Facebook login php api save cookie?
Facebook login php api save cookie?
Im currently using this facebook login php api
https://github.com/facebook/facebook-php-sdk
It works fine however when the session ends it doesn't remember the cookie
and they have to login again everytime. I got it to save the cookie using
the JS method but I really dont prefer that. How can I have it remember
the user?
Im currently using this facebook login php api
https://github.com/facebook/facebook-php-sdk
It works fine however when the session ends it doesn't remember the cookie
and they have to login again everytime. I got it to save the cookie using
the JS method but I really dont prefer that. How can I have it remember
the user?
Tuesday, 1 October 2013
Why does this error, ERROR: relation "[name of function/Views/Trigger Functions]" does not exist, come up in pgAdmin III?
Why does this error, ERROR: relation "[name of function/Views/Trigger
Functions]" does not exist, come up in pgAdmin III?
I'm just new to pgAdmin so I don't really know what causes these error:
ERROR: relation "ongoingprojects" does not exist
LINE 1: SELECT * FROM ongoingProjects;
^
*** Error ***
ERROR: relation "ongoingprojects" does not exist
SQL state: 42P01
Character: 15
Even if the Function/View exist in the schema. Why does it give that
error? And what shall I do to fix it? Thanks!
Functions]" does not exist, come up in pgAdmin III?
I'm just new to pgAdmin so I don't really know what causes these error:
ERROR: relation "ongoingprojects" does not exist
LINE 1: SELECT * FROM ongoingProjects;
^
*** Error ***
ERROR: relation "ongoingprojects" does not exist
SQL state: 42P01
Character: 15
Even if the Function/View exist in the schema. Why does it give that
error? And what shall I do to fix it? Thanks!
Within an OSX package, how can I cleanup if an error occurs?
Within an OSX package, how can I cleanup if an error occurs?
I've built application that's distributed as a flat package on OSX. It
contains both preinstall and postinstall scripts, as well as a couple of
plugins that provide custom UI. And everything seems to work just
fine....except when it doesn't. :-)
If an error occurs for any reason during install (disk space, permission
issues, etc.), there doesn't seem to be a mechanism to allow my package to
react. In those cases, I'd really like to launch a script to clean up
temporary files and remove the partially installed app altogether.
Does anyone know of a way to accomplish this? Or am I asking too much from
a package based install?
Thanks in advance!
I've built application that's distributed as a flat package on OSX. It
contains both preinstall and postinstall scripts, as well as a couple of
plugins that provide custom UI. And everything seems to work just
fine....except when it doesn't. :-)
If an error occurs for any reason during install (disk space, permission
issues, etc.), there doesn't seem to be a mechanism to allow my package to
react. In those cases, I'd really like to launch a script to clean up
temporary files and remove the partially installed app altogether.
Does anyone know of a way to accomplish this? Or am I asking too much from
a package based install?
Thanks in advance!
Putting \hat over first character of subscripted variable tex.stackexchange.com
Putting \hat over first character of subscripted variable –
tex.stackexchange.com
I'm using a set of commands to define abstractions of mathematical
notations that often occur during my thesis such as:
\newcommand{\DNoise}{n_d} which would equal some distortion noise. This
allows …
tex.stackexchange.com
I'm using a set of commands to define abstractions of mathematical
notations that often occur during my thesis such as:
\newcommand{\DNoise}{n_d} which would equal some distortion noise. This
allows …
Cool mathematics I can show to calculus students. math.stackexchange.com
Cool mathematics I can show to calculus students. – math.stackexchange.com
I am a TA for theoretical linear algebra and calculus course this
semester. This is an advanced course for strong freshmen. Every discussion
section I am trying to show my students (give them as a …
I am a TA for theoretical linear algebra and calculus course this
semester. This is an advanced course for strong freshmen. Every discussion
section I am trying to show my students (give them as a …
Subscribe to:
Comments (Atom)