I will try to implement redirect with oauth authorization in asp.net mvc4 project
controller
public ActionResult SomeName() {
if (!User.Identity.IsAuthenticated) {
return RedirectToAction("ExternalLogin", "Account", new { provider = "vkontakte" });
}
}
account
[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public ActionResult ExternalLogin(string provider) {
return new ExternalLoginResult(provider, Url.Action("ExternalLoginCallback"));
}
error
The resource cannot be found.
Description: HTTP 404. The resource you are looking for (or one of its
dependencies) could have been removed, had its name changed, or is temporarily
unavailable.
Please review the following URL and make sure that it is spelled correctly.
Requested URL: /Account/ExternalLogin
Does anybody know what I should to do?
try this:
[HttpGet]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public ActionResult ExternalLogin(string provider) {
return new ExternalLoginResult(provider, Url.Action("ExternalLoginCallback"));
}
By using RedirectToAction you are making a GET request to the url of your action, you need to accept HttpGet at ExternalLogin action on your AccountController
RedirectToAction is 302 redirect request which is GET by nature. if you are supposed to utilize your action from VIEW as well, you can use both verbs :
[HttpGet, HttpPost]
at ExternalLogin action on your AccountController accept HttpGet as other member also said.
Related
I have MVC project that use with web service to get a url and then do a redirect to the URL that i get.
In the first request(the request that return me the URL in the response) i need provider some details and one of them is successUrl.
successUrl is URL that if the action of the client in the URL that i was redirect before success so redirect to successUrl.
My question is: it possible to redirect to ActionResult? if yes What i need to send in successUrl?
Update
For Example:
I have my MVC Project and Web Service.
My controller-
public class HomeController : Controller
{
public ActionResult Home()
{
return View("~/Views/Home/home.cshtml");
}
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult CheckObject(someObject obj)
{
if (ModelState.IsValid)
{
ResponseWS responseWs = wsRequest(deatils);
}
}
[HttpPost]
public ActionResult doSomething()
{
//....do something...
}
}
The steps-
First the client go to home page from ActionResult Home().
The client fill form and click submit and go to
ActionResult CheckObject(someObject obj)
From ActionResult CheckObject(someObject obj) send request to WS
with parameters that one of them urlSuccees.
Ws return response with URL(for the example www.test.com) that i
need to redirect to it.
I do the redirect to www.test.com.
The client do something and if the client action was success the
www.test.com need to redirect to my urlSuccees.
NOTE: I want that urlSuccees will be ActionResult doSomething()
Thanks,
Tal
This is regarding to how to define routes in controller of asp.net mvc
1st controller
[AllowAnonymous]
[Route("contact/Login")]
public ActionResult Login(string returnUrl)
{
ViewBag.ReturnUrl = returnUrl;
return View();
}
2nd controller
[Route("{CategoryURL}/{Keywords}")]
public ActionResult BrowseProducts(string CategoryURL, string Keywords)
{
}
I am getting below error If try to access URL abc.com/contact/Login
Multiple controller types were found that match the URL. This can
happen if attribute routes on multiple controllers match the requested
URL. The request has found the following matching controller types:
abc.Controllers.AccountController abc.Controllers.CoursesController
My question is, I want to validate {CategoryURL} input's and also want to access URL "abc.com/contact/Login"
I have the following routes set up in a user controller:
[EnableCors("*", "*", "*")]
[RoutePrefix("api/users")]
[Authorize]
public class UserController : ApiController
{
[Route("")]
public IHttpActionResult Get()
{
}
[HttpGet]
[Route("{id:int}")]
public IHttpActionResult Get(int id)
}
[HttpPost]
[Route("validateUser")]
public IHttpActionResult ValidateUser()
{
}
[HttpPost]
[Route("verify/{identityId}/{emailAddress}")]
public void VerifyUserEmailAddress(string identityId, string emailAddress)
{
}
}
The first three routes work just fine. But the fourth fails with a 404. I'm using fiddler to make the call:
http://localhost:39897/api/users/verify/asldkfj/jb#test.com (post is selected)
Does post require data sent in the body? Can anyone see what I'm doing wrong and why the verify route is not being found?
The .com in the email is the issue.
Sure its a valid email, but IIS treats requests with file extensions as actual file requests and tries to find it on disk. When it can't find it then you get the 404 Not Found
If you add a trailing slash / to the request it should work.
ie http://localhost:39897/api/users/verify/asldkfj/jb#test.com/
We have an MVC 5.1 project and are using attribute routing. Everything is working fine except the default page which has a login form on it.
[RoutePrefix("Home")]
public class HomeController : BaseController
{
[Route("~/")]
[Route]
[Route("Index")]
[HttpGet]
public ActionResult Index()
{
var model = new LoginViewModel();
return View(model);
}
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Index(String Username, String Password)
The form is displayed via the GET fine but upon the POST we get...
HTTP Error 405.0 - Method Not Allowed
The page you are looking for cannot be displayed because an invalid method (HTTP verb) is being used.
Normally the default route would handle both the POST and GET fine.
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}/{dealerId}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
Obviously I am missing something here on the routing for the post on the default route as subsequent posts on other pages work fine.
Has anyone done this?
Thanks,
Ok seems all I have to do is add
[Route("~/")]
[Route]
[Route("Index")]
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Index(String Username, String Password)
Obvious really! Long Day!
how to redirect from a action to an external web site like paypal
public ActionResult Index() {
return Redirect("http://www.paypal.com");
}