asp.net How To allow only one Domain user - asp.net

I have looked for this issue on the internet and nothing specifies how to solve my problem.
It is a very small web application hosted on IIS7. In my web.config i have this code:
<system.web>
<authorization>
<allow users="WORKGROUP\SOMEONE"/>
<deny users="?"/>
</authorization>
<roleManager enabled="true" />
<compilation debug="true" targetFramework="4.0" />
</system.web>
When i access my website, it gives me the following error
401 - Unauthorized: Access is denied due to invalid credentials.
I want to authenticate only one domain user and I think i have used everything correctly. Please Guide Me What am i missing here

You'll need to install Windows Authentication and enable that on the IIS website.
See this post for details on how to install and configure Windows Authentication on Windows 7 and Windows Server 2008R2: http://www.iis.net/configreference/system.webserver/security/authentication/windowsauthentication

Related

Failed to load resource: the server responded with a status of 401 (Unauthorized) /App/AngularJS/angular.min.js

I am having the following error:
Failed to load resource: the server responded with a status of 401 (Unauthorized) http://localhost/App/AngularJS/angular.min.js
The project works fine on localhost. But when I run it on IIS (7.5) I get the above exception.
[Image]
My project is .net 4.5 project (Web.API 2.2), I am using AngularJS for UI in this project.
I have tried running "aspnet_regiis - i" as somewhere this was accepted as solution. But it didn't work in my case. I don't know is there any thing required to execute [AngularJS].js files on IIS for Web.API project?
EDIT:
I have made following changes to web.config file:
<location path="AngularJS">
<system.web>
<authorization>
<allow users="*" />
</authorization>
</system.web>
</location>
<system.web>
<authorization>
<allow users="*" />
</authorization>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5" />
</system.web>
Also I have set the read/write/modify access for "IUSR" & "IIS_ISURS" users of whole project.
But still I get the same exception on IIS. But same running fine with VS2013.
Error:
When servers respond with access denied message (401 Unauthorized access), it means that the anonymous IIS user account is unable to access the resources because of permission issues.
By default, IUSR account is used for anonymous user.
All you need to do is:
IIS ->
Authentication -->
Set Anonymous Authentication to Application Pool Identity.
Problem solved :)
Also I have set the read/write/modify access for "IUSR" & "IIS_IUSR"
users of whole project.
this was enough for me to get around the same issue.
PS. sorry for using your image, just want to emphasize the step you mentioned that worked for me.
Assuming that you are using form authentication and you are trying to get it before login. You can use the following in your web.config file inside <configuration>.
<location path="AngularJS">
<system.web>
<authorization>
<allow users="*" />
</authorization>
</system.web>
</location>
It will make you files inside AngularJS folder available without login
Well,
It's strange but It worked. The solution was to set the default user for "Connect as" in IIS. See the image given below.
I specified the administrator user & this started to work in IIS. I think this is some kind of requirement with AngularJS to work on IIS.
Thanks for replies.
It will work when you add IUSR into the application folder security.
I had this problem and disabled my VPN and it was solved.

Windows Authentication IIS 6 IsAuthenticated is always false

I have ASP web site using Windows Authentication.
Here are the web.config settings
<authentication mode="Windows" />
<identity impersonate="true" />
<authorization>
<allow users="*" />
<deny users="?"/>
</authorization>
When I host the website in IIS 6 the user never gets authenticated so Request.IsAuthenticated is always null in Application_AuthenticateRequest method. Same about the identity of the CurrentPrincipal.
The weird thing is that when I switch the website to use Visual Studio Dev Server, everything works brilliantly.
I have Integrated Windows Authentication ticked in the IIS web directory settings.
What am I doing wrong? Any help or advise will by much appreciated.

asp.net Problems with login : login failed for user NT Authority\Anonymous Logon

Im getting the following error when I try to login to web page with a valid username and password:
Oops. The error: Login failed for user 'NT AUTHORITY\ANONYMOUS LOGON'.
This is my web.config :
<configuration>
<system.web>
<customErrors mode="Off"/>
<authentication mode="Forms">
<forms name=".ASPXFORUM" loginUrl="login.aspx" protection="All"
timeout="30" path="/" />
</authentication>
<authorization>
<deny users="?" />
</authorization>
</system.web>
</configuration>
Anyone know what this error mean?
Could you attach the stack trace maybe? The "Oops" in the message makes me think that some code is catching the real error and returning a friendly error message. Try putting the breakpoint in there to get the stack trace.
If I had to take a wild guess, I'd say your code is trying to connect to the backend SQL Server database using integrated auth. In this is case your web application is connecting using the web server process account and failing. Try changing the connection string to use a valid SQL Server user name and password to see if the error goes away.
Have you tried putting the allow users element after the deny element, see example
<authorization>
<deny users="?" />
<allow users="*" />
</authorization>
The simple solution is to check your web.config file and make sure one of these is part of the db connection string:
Trusted Connection=false
OR
Integrated Security=True
Remove "Integrated Security=true;" from Web.Config of the application resolved this for me.
.net 4.0
WCF application
IIS7 (hosted on server1)
SQL 2005 (hosted on server2
Hope that helps someone.
Scott

Disable windows authentication on single location

I have a web application and I want to provide anonymous access to a couple of the web services in it so that we can access the web services from computers without a windows login on our network.
I've tried the stuff here Disable authentication on subfolder(s) of an ASP.NET app using windows authentication. I've done this:
<authentication mode="Windows" />
<authorization>
<deny users="?" />
</authorization>
...
<location path="Tests/QService.asmx">
<system.web>
<authorization>
<allow users="?" />
<deny users="*" />
</authorization>
</system.web>
</location>
These both "work" in that they allow access to the web service for anonymous users. However, it seems that IIS still sends an authorization challange because when I access the service from a browser I get a box to enter my username and password. If I hit cancel I get access to the page anonymously. However, some of our clients don't handle this well and just fail because of the 401 return code.
Is there a way to completely disable the windows authentication on that single location such that IIS will not try and establish a windows authentication?
You need to disable Windows Authentication on the Virtual Directory for that single location. Then you shouldn't be challenged.

Asp.net login problem

im building a asp.net web site with 2.0 framework.
I've been "fighting" with web.config, i've changed it quiet some times.
So to start from scracht this is what i have:
<?xml version="1.0" encoding="utf-16"?>
<configuration>
<connectionStrings>
<remove name="LocalSqlServer"/>
<add name="ABC" connectionString="Database=jsilvaqqc.mdf; Data Source=*****;Initial Catalog=jsilvaqqc;User ID=****;Password=*****;" providerName="System.Data.SqlClient"/>
<add name="LocalSqlServer" connectionString="Database=jsilvaqqc.mdf; Data Source=*****;Initial Catalog=jsilvaqqc;User ID=*****;Password=*****;" providerName="System.Data.SqlClient"/>
</connectionStrings>
<location path="Members">
<system.web>
<authorization>
<allow users="*"/>
<deny users="?"/>
</authorization>
</system.web>
</location>
<system.web>
<compilation debug="true"/>
</system.web></configuration>
It works fine im my machine. I've created the users for the login and the role to access the "Members" folder.
But in my host company, it doesnt work. I have the aspnet database from my computer in that databese "jsilvaqqc.mdf".
When i try to log on pops up box requiring autentication. But i've alreadu given that in the log in form.
Do i need aspnet "authentication" tag?
Why dont i need it in my machine if i access the same database?
Here is the print of the box that comes up, when i log. And only when i log with a valid user.
Link: http://www.freeimagehosting.net/image.php?c9425ff727.jpg
Thanks for you help.
It sounds like the pop-up login box you talk about is probably IIS asking for Windows Authentication. If you only want to use forms authentication, change the permissions on the Virtual Directory in IIS to allow anonymous access.

Resources