Following ExternalLoginCallback redirection fails without exception - asp.net-mvc-4

I am using a modified Internet application template for MVC4 and implemented the AuthConfig details for Twitter authentication. Following a redirect from twitter, and successful login, I get a redirect to the below URL and the webapp just dies with a Page Cannot Be Displayed error in IE with no further details:
provider=twitter&sid=XXX&oauth_token=XXX&oauth_verifier=XXX">http://domain.com/Account/ExternalLoginCallback?provider=twitter&sid=XXX&oauth_token=XXX&oauth_verifier=XXX
ExternalLoginCallback function as implemented in the template works as expected and I see a call to the local redirect which calls Home/Index. However rather than this view being rendered I see nothing happening on the site. I've used the network tracing functionality in IE to see the request details but that didn't really help me understand the issue even more.
I'm aware this is a little vague but I'd appreciate it if you let me know what I can check additionally.

I am stupid.
This is what I had in the Home controller:
if (Request.IsAuthenticated)
return RedirectToAction("Index", "Home");
else
return View();
and it was supposed to be:
if (!Request.IsAuthenticated)
return RedirectToAction("Index", "LandingPage");
else
return View();
I am sorry I asked this question but I hope there is someone else out there as stupid as I am and they may benefit from this.

Related

The Cypress test does not open the Powerapps page

I'm trying to run simple cypress test and get error like this:
but if i change visit url to another - it opens normally:
I cant understand why this does this error come with this url:
"baseUrl":"https://apps.powerapps.com/play/f1t75er8-03c9-4cc7-996d-6743cd7eac4a"
another visible error:
code:
describe("Create request", () => {
it("Should have a link that navigates to office365 login", () => {
cy.visit("/");
cy.get('div[class="loginNeededText_uf5ohz"]').contains('Sign in to start using Power Apps');
});
});
P.S. Also can't load https://apps.powerapps.com/ page. Error:
In general
With Cypress, you should not try to visit or interact with sites or servers you do not control. The main purpose of Cypress is testing, so when you try to do anything else with it, the task will become significantly more complicated (you can read more about it in the Cypress documentation).
If you really need information from a 3rd party site, it is recommended you do it through an API — mainly with the cy.request() method (e.g., Microsoft has quite an extensive documentation on how to work with the Office 365 Management API).
Your case
When you visit the apps.powerapps.com, you are being redirected to the Microsoft login page — it has a different domain name, which breaks a same-origin policy causing the cross-origin error in the Cypress console.
Seems that the page you specified in the baseUrl returns a 404 status code, along with some ugly CORS errors in the console, which suggest an issue with the app itself. After you solved those, you would most probably face the need of authentication anyway, and it is better to do it through an API.
When I use your base URL https://apps.powerapps.com/play/f1t75er8-03c9-4cc7-996d-6743cd7eac4a I see only blank screen and 404 error in the console, I am not redirected to login.
Maybe your URL should be https://apps.powerapps.com and after you login you can navigate to "/play/f1t75er8-03c9-4cc7-996d-6743cd7eac4a".

Publishing Asp.net website. This 404 error shows up. What am I missing?

Error 404 shows up after Asp.net published on GitHub. How to finish publishing. What am I missing?
I personally never deployed directly to Github before. Usually when i get a 404 error, I start by checking if all my database is linked correctly. Since secret json doesnt get pushed up when deploying, make sure you add any info in secret.json into Github.
Secondly, I comment out if logic in Startup.cs, so error shows on deployed side. This will invoke to developer exception page which you can use to diagnose what the problem is.
// if (env.IsDevelopment()) <— this one
// {
app.UseDeveloperExceptionPage(); <— have this invoked even on deployed site.
// }
Sorry i am on my phone answering but if its unclear let me know!

MVC AntiForgeryToken cookie missing in browser before login.

Application is accessed under https:// url.
In MVC application we have added ##Html.AntiForgeryToken() on cshtml razor engine and ValidateAntiForgeryToken on controller.
It all worked fine for after login pages, but with login page it goes to application error as there was no cookie seen on browser before logging into the system.
Went through several forums, articles and even added the following piece of code in global.asax.
AntiForgeryConfig.CookieName = "CSRF";
AntiForgeryConfig.SuppressIdentityHeuristicChecks = true;
//AntiForgeryConfig.RequireSsl = true; -- only for https.
Even wrote a simple SetCookie in get method of login page, that cookie doesn't show up on browser. What could be the problem.
Why i was able to see the below in cshtml but controller doesn't accept the post with antiforgeryvalidation before login.
.
Any help would be greatly appreciated

ASP.NET Core app under IIS - can't stay logged in

I am nearly finished migrating an ASP.NET Core app from RC1 to 1.1.0. Everything is working great until I try to publish the app and host it in IIS.
In a debugger, or working directly from Kestrel, I have no problems. I can reach my site, login, and interact with it normally.
Under IIS, however, I can load the site and am correctly redirected to my login page, but despite logging in with the correct credentials, I am redirected back to the home page and am not logged in. I can repeat this cycle over and over - I am authenticating, but some part of the IIS/Core middleware isn't keeping me logged in.
My site is using ASP.NET Core Identity which is largely unchanged from the RC1 default VS project template.
AccountController:
//
// POST: /Account/Login
[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public async Task<IActionResult> Login(LoginViewModel model, string returnUrl = null)
{
if (ModelState.IsValid)
{
var signInStatus = await SignInManager.PasswordSignInAsync(model.UserName, model.Password, model.RememberMe, false);
if (signInStatus.Succeeded)
return RedirectToLocal(returnUrl);
ModelState.AddModelError("", "Invalid username or password.");
return View(model);
}
// If we got this far, something failed, redisplay form
return View(model);
}
Unfortunately, I can't debug this, because the VS debugger hooks Kestrel, and when hosting natively from Kestrel this problem doesn't exist. I'm not able to attach my debugger to the running Kestrel process (that was launched by IIS) - I can get attached but my breakpoints will not attach.
I am certain that the method above is being called. If I enter an incorrect password, I do indeed see the "Invalid username and password" prompt. When I login "successfully", I am redirected to the original page. The problem is that after the redirect, I'm not logged in - the navbar still shows my Login button instead of the Logout button, and I can't interact with any authorized controllers.
I know this is a super vague question with little source, but I'm not sure where to even start with this one. I'm hoping someone might see what my problem is and point me in the right direction, or at least be able to suggest some steps I can take to isolate and try to debug the issue. Or, barring that, even some hints as to what information I can add to my question to give necessary details.
Thank you!
Two starting points you can try:
Install the latest Windows Server Hosting bundle on your server.
Monitor and compare traffic between the working and broken systems after you click the login button. Are you getting the Identity authentication cookie returned on the broken system similar to the working one?

ASP.NET Web API 2 BadRequest content

I'm not receiving the expected Response Content on the client when the resource returns BadRequest.
[HttpGet]
[Route("Test", Name = "Test")]
public async Task<IHttpActionResult> Test()
{
var result = BadRequest("test");
return result;
}
On client (see hurl.it example below) I simply receive the string Bad Request in the body:
The response on the server seems to be fine:
It was working fine at some point (returning strings or ModelState in content) and recently we noticed this problem. I can't think of any recent change on server that could cause it.
It works neither locally nor when deployed on server.
It can be reproduced in any ApiController in the project.
return Ok("test"); works as expected.
Does anyone know what can cause this behavior?
Thank you!
It is hard to tell what goes wrong.
Things you could check:
Perhaps is your error caused by invalid authentication request
Try with a new project, if that makes difference then you know it's your project and there are no errors caused by your local IIS and server settings (highly unlikely but you never know.
Check your App_Start folder, containing the BundleConfig, RouteConfig, FilterConfig,WebApiConfig`. Perhaps some custom settings did cause to give you bad request error while it might be a not found error.
Check if it's only on Get request or also on others, could be caused by different versions of assemblies.
Check if you only have the problem with 400, or does 401, 500 gives the same problem?
Check your Web.Config file, these might contain <CustomErrors> that might redirect, or throw there own errors.
After some comments, custom erros seemed to be the problem.