Windows Validation from Razor Page - asp.net-mvc

I am upgrading an application that works on an intranet, from web forms (framework 4.8) to razor page (net 6). To get a windows user using web form, do the following:
Session("Usuario") = HttpContext.Current.Request.LogonUserIdentity.Name
But I am seeing that in razor page it is not so simple; I have already set windowsAuthentication to true and anonymousAuthentication to false in the launchSetting.json file, and what it shows me is a screen (see image) for the user to enter their authentication credentials, which is not what I require, since that the user has previously validated the domain (by turning on his machine every morning in the company).
Image
I see that with the following instruction the network user is obtained in Razor, and it works, but as long as I validate myself previously on the image screen.
var username = HttpContext.User.Identity.Name;
I have also tried adding the following in Program.cs, but the same always shows that screen.
builder.Services.AddAuthentication(NegotiateDefaults.AuthenticationScheme)
.AddNegotiate();
builder.Services.AddAuthorization(options =>
{
options.FallbackPolicy = options.DefaultPolicy;
});
app.UseAuthentication();
app.UseAuthorization();
Please if you can tell me how to get the windows user without registering again, or in any case indicate if this is the normal way of working in Razor Page.
Thanks.

Related

Button not working in asp.net mvc application (environment specific)

I have a asp.net mvc application deployed in production. User can save a form in draft state and then can submit the form later. This functionality is working perfectly but for two of our users in Malaysia, when they click on Submit button, nothing is happening. It seems that the button is not working (page is not posted back).
I am unable to understand what could be the possible cause. If there is a firewall issue, then site would not have been opened at all.
Can I use fiddler to check or if there are some other options?

MVC4 External Login: Google provider button disappeared

The Problem: I used to be able to login to my MVC4 website using Google external login but suddenly the "Google" button doesn't appear. I get no such behavior when I try a new clean MVC4 project.
Debugging shows that the IsAuthenticatedWithOAuth property of the OAuthWebSecurity object throws a "Missing Method Exception" when ExternalLoginsList action in the AccountController tries to return the _ExternalLoginsListPartial view. Then, when rendering the _loginPartial view, the Request.IsAuthenticated is false. Also, the generated HTML includes the code for the button (so it means it's an authentication issue?)
The website is supposed to run on windows Azure but the problem occurs both in the cloud and when running locally. Actually the first time the button disappeared was after publishing a new version of the website to Azure.
3 hours of going round and round this and I'm not any closer to a solution.
Badly need help here. Thanks

What happened to the popup dialog in asp.net mvc4

I am fairly new to mvc and I tried mvc4 when it was still in beta. I remember that when I started a new internet project, I got a popup dialog for log in and registration by default. I don't see that when I start a new project anymore, is that gone from the internet project?
I believe the popup dialog you're referring to was just the jQuery UI Dialog that the sample project used to use:
The project was built to support both a straight request to /Login and one via the jQuery UI dialog which was slimmed down to look like it was only a popup. It did this by making the Login action return a different View based on it being requested through the frame or not as detected by a value in the query string.
You can of course have this again, you'll just need to do it manually (or dig out one of the older templates) as it's no longer in the default templates.
To help you out, here's a couple of somewhat related questions that contain the sample code (ContextDependentView is one thing I remember from this template) and probably some hints on how to recreate it:
Generating a modal jQuery partial view with MVC4 does not work
ASP.NET MVC 4 and ContextDependentView
MVC4 - ContextDependentView - What does it mean?
It was removed from the Internet project templates in the final releases of MVC 4. The popup was pretty slick but I imagine there were issues/complexities they decided to eliminate by just keeping the view/page for logon and registration. In the older versions that had the pop-up they still had the view/page for logon because of how forms based authentication works. If the user is not authenticated/authorized for a web site/page MVC does a redirect to the logon page. This will not work with a JQuery popup dialog on the same page. The popup only worked if you clicked on the Logon link for the page. I am guessing that they decided since they need the view/page logon anyway to simplify things and keep it consistent by eliminating the popup dialog.
I have implemented an MVC Single Page Application (SPA) that only uses a JQuery dialog for a popping up a dialog for logon, and eliminates the need for logon page. But it required a fair amount of customization to authentication/authorization process on the server and used basic authentication on the client.

Problems with ASP.NET MVC 4 Display Modes and Forms Authentication

I have an ASP.NET MVC 4 application that uses forms authentication (I started with the ASP.NET MVC 4 mobile template). I have also added display modes functionality to support mobile devices. However, forms authentication doesn’t seem to work with these different display modes.
In Global.asax Application_Start, I have
DisplayModeProvider.Instance.Modes.Insert(1, new DefaultDisplayMode("iPhone")
{
ContextCondition = (context => context.GetOverriddenUserAgent().IndexOf("iPhone", StringComparison.OrdinalIgnoreCase) >= 0)
});
to register a display mode for an iPhone.
In ~/Views/Shared, I have _Layout.cshtml for desktop browsers and _Layout.iPhone.cshtml for iPhones. In ~/Views/Home, I have Index.cshtml for desktop browsers and Index.iPhone.cshtml for iPhones. In ~/Views/Account, I have the standard .cshtml files that come with the ASP.NET MVC 4 mobile web template (Index, Login, Register, etc.).
In FilterConfig.cs RegisterGlobalFilters, I added filters.Add(new System.Web.Mvc.AuthorizeAttribute()); so that authentication is needed to navigate anywhere in the site (except the AccountController, which has [AllowAnonymous] on the Login and Register action methods).
This is all basic stuff and set up correctly. When navigating to the site in the browser (from both a desktop browser and an iPhone browser), the display modes settings/configuration works great and I’m taken to either the normal .cshtml files or the iPhone-specific files.
The problem occurs when adding forms authentication.
When I first go to the site, since I’m not authenticated, I’m redirected to the Login page (as expected). The URL shows as http://localhost:63087/Account/Login?ReturnUrl=%2f . After logging in, I’m redirected back to the root and on to the correct display mode. All fine.
However, the URL doesn’t change. It stays as http://localhost:63087/Account/Login?ReturnUrl=%2f . This is a problem. Now any future navigation gets confused and sends me back to the Login page (even though I’ve already logged in and was authenticated).
How can this problem be fixed?
How can an ASP.NET MVC 4 application with multiple display modes be made to work correctly with forms authentication?
Thanks.

ASP.NET MVC Windows Security issue

I am suddenly getting a Windows Security dialog when requesting:
http://mydomain/Reports/
This happens after I have moved an ASP.NET MVC application from Server 2008 to Server 2008 R2.
This page (like others) are access controlled using Windows Form authentication. The other pages work correctly, just this page is giving me hassles - and only on this server.
Even signing in with my domain credentials fails; after the third failed login a blank page appears.
I have disabled Windows Authentication in IIS and enable Form Authentication.
The request executes:
public ActionResult Index()
{
return View();
}
The index.aspx page associated to his page contains static HTML.
Any ideas what might be causing this?
Update to comments and questions:
Site (mydomain) is running as a web site on its own.
SSRS is installed on the machine but not part of this web site.
Changing the controller name to ReportController instead of ReportsController causes it to work. Something is processing Reports first, where can I find it? I don't see any Reports folder or web sites on the server...
When upgrading sql server, often it adds a virtual directory or virtual application in iis called Reports and ReportManager. Just went through this, so it's worth checking out.
Check the permissions on the folder or file, they are probably not set correctly so IIS is trying to get a valid set of credentials to continue.
Also, is that Reports folder running, say, SSRS?

Resources