Get intranet authenticated user - c#

I am building a web application for my school's intranet. Whenever teachers try to access the browser to access the intranet page a popup appears so they can login, in my page I need to get the logged username. do any of you guys know how to do that?
System.Security.Principal.WindowsIdentity.GetCurrent().Name.ToString();
The code above is what I've managed to do so far which gets the username of the user loggin in on windows but that's not really what I want.

you can use simply the following statement :
HttpContext.Current.User.Identity.Name

Related

ASP.NET MVC User.Identity.Name is Blank

I am attempting to build an ASP.NET MVC website which allows certain domain users to login and access the various functions it offers. I'm building this using Azure AD which Azure has a really nice way of letting you download a pre-built application which comes withe a Windows login page and authenticates the user already.
Here is the login page. It is even pre-populated with my domain.
Username#mydomain.com
After a successful login however the User.Identity.Name property is null.
I did some searching online and found a ton of posts like this that recommended turning Anonymous Authentication off and Windows Authentication on in the project properties. I gave that a shot but it automatically signs me in, completely bypassing the login page, and the User.Identity.Name is the name of the PC I'm developing this on. Is there a way to have Windows Authentication enabled and still have the login page working?
EDIT 1:
I forgot to mention, the User.Identity.Name property is null after the user has been authenticated for login.

Asp.Net Windows Authentication with Long Usersnames

I am having this strange problem with Windows Authentication in ASP.NET.
A user complaints that he cannot use his username to access one of my systems. However, the username is correct and every other user is able to access it.
When I tried to use my C# code to query the Active Directory to look for that user, I get an error that the user is not there! But, he is.
when I sent this to our technical team, they said that it is because the username is "too long" and then they gave me another one. which worked.
how can a user have an active username on AD and still cannot use it to login to ASP.NET web app
any idea?

ASP.NET forms authentication is screwy after RewritePath

I have a problem which I can't replicate on my dev server (IIS 8.5), but which is happening on my live server.
The ASP.NET website uses forms authentication, which works perfectly unless the URL is rewritten. On rewritten URLs, the user is not considered logged in. If you click "log in", then the user is logged in without redirecting to the login form! This means the cookie is somehow being used to authenticate the user after clicking "log in". Refreshing the rewritten page reverts to not being logged in.
Here are some concrete examples:
Go to http://www.paraglidingmap.com and log in with the following details (top right of the screen):
Username: test
Password: hibiscus
Now go to this page which uses URL redirection, and you will not be logged in! But if you click "log in", you will be magically logged in until you refresh the page.
http://www.paraglidingmap.com/page/AppAndroid
Someone out there must be smarter than me. Why is this only happening on the live server and not dev? I have checked that integrated pipeline is used on both servers.
I have found a solution. Instead of using HttpContext.Current.RewritePath, using Context.Server.TransferRequest seems to also transfer the request cookie.
I would be grateful if anyone could explain why this is the case.

Get currently logged-on Active Directory user from a C# web page (IIS incl)

We are building an intranet for a client, the client doesn't want the users to log on, as they have already logged onto the domain (Active Directory)
But they do want to know the AD username of each user so that if they post on the blog, their identity can be recorded.
Our thinking so far has been, that our web.config file should say:
<identity impersonate="false" />
so that each user browses the intranet site as themselves and not the App Pool user configured in IIS.
Would this be the right way to go about it?
If so, what IIS authentication should we be using? NOTE: we are not authenticating the user, so we don't want the logon prompt, all users will already have logged onto the domain, we just want to see their username.
Is this even possible? And are we on the right track?
In C#, we can retrieve the username like this:
System.Web.HttpContext.Current.Request.LogonUserIdentity.Name.ToString()
but we just can't find an IIS authentication setting that will not prompt a domain/network login.
You need to turn on windows authentication. After you did that, the identity token will be passed to the server as I remember, and you can manage the authentication with that.
Also note that only Chrome and IE supports this fully, Firefox will ask at least for pressing an ok button before authenticating the user.
Other thing to note is the set the trust levels correctly in the browser, or it wont do the automatic authentication.
You already know how to get the LogonUserIdentity and set up IIS correctly. What is lacking is to get the browser to automatically authenticate with the AD account of the user. To enable that you have to configure the browser to do so, which I think only is enabled for Intranet zone sites by default.

Passing user and password to Sharepoint

this is my scenario: I'm developing a web application where the user logs in, when he clicks a link I want him to be redirected to a Sharepoint site and I want to automatically pass to Sharepoint his username and password, therefore he doesn't need to log in.
How should I do this? Please indicate me the best strategy. I have already tried with this, but it did'nt work out.
http://forums.asp.net/t/883397.aspx
The login via NetworkCredential seems to work fine, but when I redirect my page to Sharepoint it prompts me again for user and password.
Thanks in advance.
We did something like this on a application I was working on (although it wasn't a SP site). You want to setup the web.config so that both site can decode the authentication token (cookie) that is set in your web application. Take a look at this article on MSDN that describes how to configure forms authentication across applications.

Categories

Resources