Routing in Net Core 5 - c#

I have an application developed using C# under Net 5. The issue I am facing is only happening when I access the site remotely as it is already published on IIS, otherwise running it directly from Visual Studio seems to work rather fine.
Below is my "Index" View :
<form method="post" asp-action="GenerateOTP" asp-controller="Home">
Below is the controller:
[HttpPost]
public ActionResult GenerateOTP(OTPData mydata)
{
...
return RedirectToAction("EnterOTP", "Home");
}
Basically the app should automatically redirect to the page "EnterOTP" after performing the commands on the "GenerateOTP" method. Instead on production the page redirects to Home/GenerateOTP on the browser and this would definitely not work as the page doesn't exist.
Any recommendation on what I am missing.

#PanagiotisKanavos Thanks for the tip. Checked my Event Viewer and found out the issue was on my ApplicationPool Identity. It wasn't authorized access to that directory. Changed it from ApplicationPoolIdentity to LocalSystem and all works fine right now.

Related

IdentityServer on Azure

I'm trying to make an ASP.NET Core Web application to host IdentityServer and use it as my main authorization service, shared across many other apps.
I followed the quick start tutorial that consists in installing a nuget package (called IdentityServer4) in an empty MVC application template.
Everything is working fine on my machine (debugging with VS2017 & VS2019 preview).
I tried to publish the app as an Azure App Service like i did with previous apps and worked fine.
While debugging, if i open a browser and type "https://localhost:44316/", i see this page:
But navigating to "https://xxx.azurewebsites.net" (that is where i published the app) is not working. Responding 404 not found.
Just to add some detail, if i navigate this "https://localhost:44316/Account/Login?ReturnUrl=%2Fgrants", i obtain the correct login page and doing the same on Azure produces the same result.
So, essentially, looks like it's working, except for the home page.
I'm not an expert in routing with ASP.NET Core, so don't blame me if my question is not so smart.
So, essentially, looks like it's working, except for the home page.
This is actually the intended behaviour - If you take a look at the implementation of the HomeController provided in the IdentityServer4.Quickstart.UI project, you'll see the following implementation (source):
public IActionResult Index()
{
if (_environment.IsDevelopment())
{
// only show in development
return View();
}
_logger.LogInformation("Homepage is disabled in production. Returning 404.");
return NotFound();
}
When running in Azure, the application's environment isn't set to Development environment and so returns 404 NotFound, as shown above.

MVC - Post Route Not Working in IIS

I have an MVC project that works fine when in VS.
But when I publish it and use it in IIS, a search page always gives this result:
No web page was found for the web address:
My controller has these two options:
[HttpPost]
[Route("[controller]")]
public IActionResult Search(SearchModel model)
&
public IActionResult Index(SearchModel model = null)
The page will load normally but once I perform the search in IIS it just wont work, any idea why this would be when VS handles it just fine.
Just incase this incredibly rare issue occurs for someone else!
I have finally managed to correct the fault by slowly removing code from the error page until it finally loaded.
The problem was making a call to a method in a class that made use of HtmlAgilityPack and Fizzler.
For some reason MVC cannot handle it, and not a single error of relevance was offered anywhere!!
I uninstalled both and found an MVC specific version in nuget packages.. Lord!

ASP.NET MVC site always redirects to log-in page

This has got me baffled! I've just created a new site using identity framework 2, and it all works fine except that it always shows me the login page. I've spent some time looking at possible answers on the Internet, so let's eliminate some possibilities.
On my home controller, I haven't got an [Authorize] dressing - and just for good measure, I stuck on [AllowAnonymous] to check this didn't help:
I don't think I've got any filters which are applying authorisation to all pages:
Here is part of my web.config:
The strange thing was that when I first created the site, it worked. I then dressed the home controller with the [Authorize] attribute, which forced me to log in. That all worked too. It's only now that I've removed the [Authorize] attribute that things aren't working.
I'm sure I'm being a bozo, but can't work out why. I've rebuilt my solution, exited and re-entered Visual Studio 2015, etc. I'm using MVC 5 and entity framework 6.
Thanks in advance!
The web config should overwrite the IIS express config but in this case it seems it does not. What you can try to do is to turn it off on the IIS level as well.
You can go to this directory \IISExpress\config\applicationhost.config open up this file and set the <windowsAuthentication enabled="false" />.

MVC 3 Forms Authentication not working in Internet Explorer keeps redirecting to login page

I have implented some lovely forms authentication in ASP.NET MVC 3, this has been working fantastic in Chrome. Now is the time test on the worlds worst browser, Internet Explorer. I just simply went to Log in, and the page just goes back to the login in page every time I click the submit button. The credentials are correct. I have stepped through the code, I am using a RedirectToAction to a page and no errors are being flagged it just goes straight back to the login page.
I should point out I have tried the following:
Removed webmatrix dlls and dependancies
Removed System.Web.Helpersn
These have both been removed from the bin, the references and the
bin_deploayableAssemblies folder in VS2010
I have also dded the following to the web.config appsettings:
<add key="enableSimpleMembership" value="false" />
<add key="autoFormsAuthentication" value="false" />
<add key="loginUrl" value="~/LoginReg/LogOn"/>
Here is my full web.config:
http://pastebin.com/t6cj6cSb
I should point out my login page is in a folder called: Login Reg, so the url would be /LoginReg/LogOn.
This works perfectly in chrome but for some reason doe not work in Internet Explorer.
Does anyone have any ideas hwo to fix this really annoying problem or have any useful articles
Thanks
Forms authentication creates a http cookie to maintain authentication state between requests. Make sure you have cookies enabled in IE.
I found a weird solution to this problem, In my case, I have an MVC3 Solution, and of course my problem was the same as the original post,
What I did is very weird:
I renamed the LogOn get/post method(s) to LoginPageView
Of course I created the corresponding VIEW to the LoginPageView Controller action
[HttpGet]
public ActionResult LoginPageView()
{
return View();
}
I ran and I could redirect to any other controller action on the solution, of course taking care of the [Authorize] or not authorize attribute on my methods I need.
Problem Solved.
Here is the solution that resolved my issue by adding a global filter to FilterConfig.cs file.
public class FilterConfig
{
public static void RegisterGlobalFilters(GlobalFilterCollection filters)
{
filters.Add(new AuthorizeAttribute());
}
}
Now login works perfectly with Internet explorer and Microsoft Edge browser.

MVC site using relative paths for links instead of view syntax

EDIT!! I should add that this site runs perfectly locally. It's only when deployed that there's this issue
ORIGINAL POST:
I have a site I just put up http://splattonet0.web704.discountasp.net/
Which loads the Index view of the Home controller just fine. However, when one clicks the links to the left, the webserver is looking for the relative paths (ie E:\web\splattonet0\htdocs\Home\AboutMe) which is incorrect, since Home folder is of course under a folder called "Views"
I've made MVC sites before and have never had this problem. I can't see any difference between this or any other site I've done.
My code in my master template for the link section is as follows:
<div id="navContainer">
<ul id="mainNav">
<li>Home</li>
<li>About Me</li>
<li>Skills</li>
<li>Resume</li>
<li>Experience</li>
<li>My Websites</li>
<li>References</li>
<li>Projects</li>
<li>Hobbies</li>
....etc
</ul>
</div>
I have the same problem with and without the preceeding foreslash in the href property. I've decided to keep it there since that is how my other sites (that work!) are styled.
Can anyone shed some light on this for me? Thanks!
FURTHER EDIT:
I have been asked to provide code from an MVC site on this server I have written and that works fine. The link code in the other site (YorkCentre) is the same style: <li>text</li>
The code:
<li>Archived News</li>
<li>Board Of Directors</li>
<li>In The Media
...
</ul>
/Home/Index should be calling the "Index" action of the "Home" controller, assuming you're using default routes. The fact that "Home" is under the "Views" folder is irrelevant for MVC.
If the code is the same in both locations, and the issue only happens in one, perhaps the answer lies not within the code. The following are some troubleshooting tips which may help, as I don't know exactly what the issue is without more information about the two environments.
What are the web server platforms for your local environment and the server environment? Are you using Visual Studio and Cassini locally, and IIS remotely? If so, which version of IIS? If not, what is the platform? In any event, is the target server configured correctly?
Check to make sure your routes are set up correctly on the target server. This is especially true if your target server runs IIS6 -- IIRC, IIS 6 needs some special configuration help to deal with the standard routing in ASP.NET MVC.
If all of the above don't help you trace this out, try to replicate it locally by creating a new MVC site and merely dropping your existing files into it. See if that succeeds or fails.
Do you have other successfully-executing ASP.NET MVC apps on that server? Check their configurations against your new site's.
I have resolved the problem! In DiscountASP I have changed the Application Pool Pipeline Mode from Classic to Integrated and that results in my views being properly rendered.

Categories

Resources