I'm trying to create a basic application, i created facebook application before but everything has been changed :(
I looked every where to create a basic application, but now i'm getting mad because there isn't any working sample. Because of the changed links, facebook api changes, facebook wiki changes i couldn't find a working copy.
I wonder if anyone can help me to write a basic app that gets permission to write user name to screen in facebook developer toolkit asp.net. I looked computerbeacon.net, codeplex, and some other pages but i couldn't succeed, so please don't give me the links :)
Edit: I' m adding some screenshots and some codes, it will may be help you to find my problem.
Here some screenshots from fb;
This is the core settings,
This is the Facebook integration settings,
Web.config file
<?xml version="1.0"?>
<configuration>
<appSettings>
<add key="FaceBookAPIKey" value="MyapiKey"/>
<add key="FaceBookSecretKey" value="MyapiSecret"/>
</appSettings>
<system.web>
<compilation debug="false" targetFramework="4.0" />
</system.web>
</configuration>
My Default.aspx file;
<%# Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<%# Register Assembly="Facebook.Web" Namespace="Facebook.Web" TagPrefix="cc1" %>
<cc1:CanvasFBMLLoginControl ID="CanvasFBMLLoginControl1" runat="server" RequireLogin="true" />
Result;
Thanks
I faced the same problems.
please make sure that
please fill canvas url with your webapp correct URL when you create facebook application
I paste here the following running example that update my status in facebook profile
the following code in markeup
<script type="text/javascript" src="http://static.ak.connect.facebook.com/js/api_lib/v0.4/FeatureLoader.js.php"></script>
<form method="post">
<input type="submit" value="Submit Comment" />
<%--<fb:login-button></fb:login-button>
<fb:prompt-permission perms="status_update"> Grant permission for status updates </fb:prompt-permission>
</form>
and the following in form page to send status
/// <summary>
/// To send status to your facebook account
/// </summary>
/// <param name="statusMessage">status message</param>
public bool publishToFaceBook(string statusMessage)
{
//please Change call back url in FB app accoroding to your web site application
Facebook.Rest.Api Api;
Facebook.Session.ConnectSession _connectSession;
_connectSession = new Facebook.Session.ConnectSession(ConfigurationManager.AppSettings["FaceBookAPIKey"], ConfigurationManager.AppSettings["FaceBookSecretKey"]);
bool sucess=false;
if (_connectSession.IsConnected())
{
try
{
Api = new Facebook.Rest.Api(_connectSession);
Facebook.Schema.user u = Api.Users.GetInfo();
Facebook.Schema.user_status _status = new Facebook.Schema.user_status();
Api.Users.SetStatus(statusMessage);
sucess = true;
}
catch (Exception ex)
{
sucess = false;
}
}
return sucess;
}
I hope that help you
Best Regards,
Mohammed Thabet Zaky
Related
I am attempting to implement a Captcha on a partial view of a page in my application. I have the captcha being refrenced through web.config as a control. I have used the GenericHandler and Class file from this forum post: http://forums.asp.net/t/1871186.aspx/1
How can I reference the user's input if i am using a simple input tag? Should I use an HtmlHelper instead?
<div class="captcha">
<rhcap:Captcha ID="Captcha1" runat="server"></rhcap:Captcha>
<input type="text" id="UserCaptchaText"><input/>
<%= Html.TextAreaFor(m => m.UserCaptcha) %>
</div>
<%if(Captcha1.Text != /* How can get the users input here?*/ ) {
//display error
}else{
//proceed
}%>
Use NuGet and install Recaptcha for .NET (supports MVC as well)
http://nuget.org/packages/RecaptchaNet/
Documentation is on the site:
http://recaptchanet.codeplex.com/
There are other captchas:
http://captchamvc.codeplex.com/
EDIT:
This project has moved to GitHub
https://github.com/tanveery/recaptcha-net
NuGet Google reCAPTCHA V2 for MVC 4 and 5
NuGet Package
Demo And Document
Web.config File in the appSettings section of your web.config file, add the keys as follows:
<appSettings>
<add name="reCaptchaPublicKey" value="Your site key" />
<add name="reCaptchaPrivateKey" value="Your secret key" />
</appSettings>
Add Recaptcha in your view.
#using reCAPTCHA.MVC
#using (Html.BeginForm())
{
#Html.Recaptcha()
#Html.ValidationMessage("ReCaptcha")
<input type="submit" value="Register" />
}
Verifying the user's response.
[HttpPost]
[CaptchaValidator]
public ActionResult Index(RegisterModel registerModel, bool captchaValid)
{
if (ModelState.IsValid)
{
}
return View(registerModel);
}
EDIT:
You should also add this in your head tag or you might see improper captcha
<script src="https://www.google.com/recaptcha/api.js" async defer></script>
First off, it looks like you are mixing standard ASP.NET and ASP.NET MVC. If you want to do MVC, the standard way to do it is the Html.TextBoxFor() type of stuff, and then you handle the value of that in a controller action method rather than write something inline in the page. So you have something like this:
Page.aspx
<rhcap:Captcha ID="Captcha1" runat="server"></rhcap:Captcha>
<%= Html.TextBoxFor(m => m.UserCaptcha) %>
and then in:
SomeController.cs
[HttpGet]
public ActionResult Page()
{
// generate captcha code here
ControllerContext.HttpContext.Session["Captcha"] = captchaValue;
return View(new PageViewModel());
}
[HttpPost]
public ActionResult Page(PageViewModel model)
{
if (model.UserCaptcha == ControllerContext.HttpContext.Session["Captcha"])
{
// do valid captcha stuff
}
}
To take this to the next level would be to implement it in a FilterAttribute. But this should work for most uses.
I would recommend you to use Google reCAPTCHA, is the best and easy to implement plus it comes with the trust of Google.
Very very effective and easy to implement.
Read this article written by me on implementing Google reCAPTCHA in ASP.NET MVC
Thanks
I am following Stephen Walther's guide and everything builds without errors. However once I run the application in Chrome I get this error message:
Application Cache Error event: Failed to parse manifest http://localhost/website/Manifest.ashx
And nothing is cached.
From what I have gathered from here, I have a type-o in my manifest. Maybe you can see something I did wrong and causing this error message.
Manifest.ashx:
<%# WebHandler Language="C#" Class="JavaScriptReference.Manifest" %>
using System;
using System.Web;
namespace JavaScriptReference {
public class Manifest : IHttpHandler {
public void ProcessRequest(HttpContext context) {
context.Response.ContentType = "text/cache-manifest";
context.Response.WriteFile(context.Server.MapPath("Manifest.txt"));
}
public bool IsReusable {
get {
return false;
}
}
}
}
Manifest.txt:
CACHE MANIFEST
CACHE:
Images/img1.jpg
Images/img2.jpg
JScript.js
Default.aspx.vb
# Does Default.aspx.vb even need to be cached?
TLDR: Don't add a CACHE: entry in your manifest, don't cache code-behind files and make sure you registered the HttpHandler in your Web.Config
Long Version:
There are a few things that you need to do to make the sample app work. First up you create your handler as above, an example in C# is:
using System.Web;
namespace CacheTest
{
public class Manifest : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/cache-manifest";
context.Response.WriteFile(context.Server.MapPath("Manifest.txt"));
}
public bool IsReusable
{
get
{
return false;
}
}
}
}
Next you need to register the handler in your web.config like:
<configuration>
<system.web>
<httpHandlers>
<add verb="*" path="Manifest.ashx"
type="CacheTest.Manifest, CacheTest" />
</httpHandlers>
</system.web>
</configuration>
Next up create a Manifest.txt in the root of your website and populate it. The sample should not have a CACHE: heading inside it. A working sample may look like:
CACHE MANIFEST
# v30
Default.aspx
Images/leaping-gorilla-logo.png
Note that we do not cache code behind files, only relative paths to actual resources that a browser may request. Finally, add a Default.aspx file. Ignore the code behind but edit the markup so that the initial HTML tag references the HttpHandler, the full markup:
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="CacheTest.Default" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" manifest="Manifest.ashx">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
This is a sample offline app!
</div>
</form>
</body>
</html>
With this done you can now start your website, browse to it in FireFox and you will be asked permission to take it offline. Alternatively, fire it up in Chrome, switch to the developer tools, check the Resources tab and you will be able to see the resources that have been loaded under the Application Cache node:
And for completeness, your finished code structure will look like:
The error "Application Cache Error event: Failed to parse manifest" can be caused by formatting of the text file.
My deployment script generated the manifest file in Unicode. The file looked fine in Chrome (when going to the URL), validated on online validators, but would generate this error when being used as a manifest.
To fix the file, just open the manifest file in notepad and go to "Save-As" and select UTF8.
I'm using Crystal Reports in a Webform inside of an MVC application. Images in the reports are not being displayed, however, on both the ASP.NET Development Server and IIS 7 (on Win7x64).
I know from a number of other questions similar to this that the CrystalImageHandler HTTP Handler is responsible for rendering the image, but I've tried all of the usual solutions to no avail.
So far, I have
Added the following to my appSettings (via http://www.mail-archive.com/bdotnet#groups.msn.com/msg26882.html)
<add key="CrystalImageCleaner-AutoStart" value="true" />
<add key="CrystalImageCleaner-Sleep" value="60000" />
<add key="CrystalImageCleaner-Age" value="120000" />
Added the following httpHandler to system.web/httpHandlers (via https://stackoverflow.com/questions/2253682/crystal-report-viewer-control-isnt-loading-the-images-inside-the-report)
<add verb="GET" path="CrystalImageHandler.aspx" type="CrystalDecisions.Web.CrystalImageHandler, CrystalDecisions.Web, Version=12.0.2000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304"/>
Added the following to my Global.asax.cs (via Crystal Reports Images and ASP.Net MVC)
routes.IgnoreRoute("{resource}.aspx/{*pathInfo}");
and
routes.IgnoreRoute("CrystalImageHandler.aspx");
Any ideas as to why the images still 404?
I had similar problem. This helped me.
routes.IgnoreRoute("{*allaspx}", new { allaspx = #".*(CrystalImageHandler).*" });
I've tried the multitude of ways this can supposedly be made to work. None did. So I eventually settled on cheating:
public class CrystalImageHandlerController : Controller
{
//
// GET: /Reports/CrystalImageHandler.aspx
public ActionResult Index()
{
return Content("");
}
protected override void OnActionExecuted(ActionExecutedContext filterContext)
{
var handler = new CrystalDecisions.Web.CrystalImageHandler();
var app = (HttpApplication)filterContext.RequestContext.HttpContext.GetService(typeof(HttpApplication));
if (app == null) return;
handler.ProcessRequest(app.Context);
}
}
I added a route to this controller matching what Crystal expects (./CrystalImageHandler.aspx) and used this controller to invoke the handler when the action is executed. Not pretty, but functional.
Have you tried adding it to system.webServer/handlers? That should fix it on IIS7 but it is strange it doesn't work on the development server w/o that.
Add this in RouteConfig.cs file
routes.IgnoreRoute("Reports/{resource}.aspx/{*pathInfo}");
Note
"Reports" is the folder name which contains the aspx file of report viewer
change this folder name as per your application
i want disable RequestValidation on particular view in ASP.NET MVC 2.0 RTM. so i added some necessary to view Page directive section as below:
<%# Page ValidateRequest="false" Language="C#" MasterPageFile="Path" Inherits="System.Web.Mvc.ViewPage<Path>" %>
but RequestValidation isn't Disabled! i also added RequestValidation Attribute to related action in controller as below:
[System.Web.Mvc.ValidateInput(false)]
public System.Web.Mvc.ActionResult Create(Model instance)
{
//Do here something
}
:') but RequestValidation isn't Disabled too!
in last try i set RequestValidation to false in Web.config file as below:
<pages validateRequest="false" />
RequestValidation still isn't turned off!
Why? thank's in advance ;)
If you are using asp.net 4.0 the validate request feature behavior has been changed from version 2.0. Check out the breaking changes document here. If this is the case you can resolve the problems by setting the request validation behavior back to the 2.0 in the web.config like this:
<httpRuntime requestValidationMode="2.0" />
just add
[ValidateInput(false)]
in your controller function
but don't forget to encode the value to prevent harmful code
[ValidateInput(false)]
public string Browse(string test)
{
string message = HttpUtility.HtmlEncode("Value = " + test);
return message;
}
I'm trying to develop my first site in ASP.Net using Web Forms.
I have a form with some controls and a TextBox control. While now I use GETrequest. When user submits a form his browser expects to get long URL, something like
http://mysite.com/search.aspx?__VIEWSTATE=%2FwEPDwUJNTE2NjY5jMY4D2QWAgICD2QWAgIDDW8wAh4EVGV4dAUBMWRkZKthQ0zeIP5by49qIHwSuW6nOj8iLTdoCUzpH369xyg8&__EVENTVALIDATION=%2FwEWAwLnrcHhBQLs0bLrBgKM54rGBjGtX5fJOylLy4qRbt6DqPxO%2FnfcMOkHJBRFqZTZdsBD&TextBox1=sfs&Button1=Button
if his input is a word sfs in TextBox1.
So I need to return him response. I would like to show this response on a user-friendly URL like
http://mysite.com/search.aspx?TextBox1=sfs
or
http://mysite.com/sfs
or
http://mysite.com/search/sfs
How can I do that? If I use Response.Redirect, it first returns 302, and only then work on short URL. Server.Transfer doesn't change URL and user sees ugly long URL in browser.
It seems to me that it is possible to solve via RouteCollection.MapPageRoute which appeared in 4.0 Framework but it's unclear to me how I can use it.
Any help is appreciated.
UPDATE. It is not a problem to use POST instead of GET. But in this way URL will always look like http://mysite.com/search.aspx
UPDATE2. The form MUST be server control and it has another controls except submit and textbox. It would be good (though, still, not necessary if this parameters don't appear in URL showing in the browser.
Using GET requests with ASP.NET server forms will unfortunately always yield those "ugly" URLs.
One thing that you can do is change the form to not be a server form and instead be a regular form:
<form method="get" action="Search.aspx">
<input type="text" name="query" />
<input type="submit" name="SearchButton" value="Search" />
</form>
One limitation of this solution is that you can no longer place certain ASP.NET controls within this form. For example, the <asp:Button> control will not work in this form because it must be contained within a server form (that is, a form that has runat="server" on it).
Since its a GET request you can also use javascript, setting the
location.href = 'http://mysite.com/search/' + query;
Then on the ASP.NET side you can use the URL Rewriting feature to redirect that url to a specific ASPX page as a query string parameter.
Let me know if you would like a more detailed sample.
Sample:
Here is a sample, please note I haven't tested it, but this should get you started.
<html>
<head>
<script type="text/javascript">
function searchRedirect()
{
var query = $get('query');
location.href = "/search/" + query.value;
}
</script>
</head>
<body>
<div class="search">
<input type="text" id="query" /><br />
<input type="button" id="search" value="Search" onclick="searchRedirect();" />
</div>
</body>
</html>
Then on the redirect side you have have a RouteModule like this:
public class UrlRewriter : IHttpModule
{
public void Dispose()
{
}
public void Init(HttpApplication context)
{
context.AuthorizeRequest += new EventHandler(OnBeginRequest); //this ensures the login page has the vitual url not the mapped url
}
private void OnBeginRequest(object sender, EventArgs e)
{
var application = sender as HttpApplication;
if (application != null)
{
var requestPath = application.Request.AppRelativeCurrentExecutionFilePath;
if (requestPath.ToLower().StartsWith("/search/"))
{
var query = requestPath.Substring(8);
application.Context.RewritePath("Search.aspx", null, "query=" + query, false);
}
// .. Other Routes
}
}
}
And assuming the code is in your App_Code folder you could use this in your web.config
<system.web>
<!-- ... -->
<httpModules>
<add name="UrlRewriter" type="UrlRewriter, __code"/>
</httpModules>
</system.web>
<!-- If IIS7 -->
<system.webServer>
<modules>
<add name="UrlRewriter" type="UrlRewriter, __code" />
</modules>
</system.webServer>
Well, the main thing that's making that 'look bad', is you're using ViewSate and GET; so don't do that (either disable the ViewSate and adjust code accordingly, or use POST).
What you may also be interested in, however, is URL Re-Writing. You can do that in a few ways, I typically do it with a wildcard mapping in IIS and appropriate changes to the Global.asax file. Searching will reveal how to do this.