Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

MVC4 Window authentication without prompt

Posted on 2014-02-25
Last Modified: 2014-03-17
Hello Experts,

I am working on porting of Asp.Net WebForm to MVC4 application.

** The website and users who will access websites are in same domain.

In old website users were restricted by creating a separate folder with web.config allowing only users with Admin role as -

      <allow users="?" />
      <allow roles="Administrators" />      

Open in new window

So to implement same in MVC on Admin controller, I marked controller as -

[Authorize(Roles = @"Administrators")]
public class AdminController : Controller

Open in new window

Questions :

Q.1. After publishing on server, when I try to access respective controller, the browser show prompt asking for username and password.

* I know of that it is browser normal behaviour to show that. But if it is true, then why it is not showing same prompt for earlier website?

Q.2. I am looking for some sort of solution that allow me to following -

(i) Get window's logged-in username that is making request.
(ii) Check role of that user matching with roles defined by me (for e.g. in web.config).
(iii) Authorize or allow user to access controller basis on result of step 2.

* I'm aware that I can get logged username by HttpContext.Current.User.Identity.Name. But it is returning me null if I am not using Window Authentication. And if I am using WA, then it will work. But again a prompt window comes.

I belive that I'm not only the one who is facing this problem or had faced same for MVC. There might be other experts who fixed this for their websites. So looking for practical solution or hints.

I want to allow access to specific controller for specific users with Admin role using their logged in credentials (without asking them for their credentials with prompt again).
Question by:Vikram Singh Saini
  • 3
  • 2
LVL 96

Expert Comment

by:Bob Learned
ID: 39887817
There are some ideas here to investigate:

Authenticating Users with Windows Authentication (C#)

If, on the other hand, you are using IIS with Anonymous authentication disabled and Basic authentication enabled, then you keep getting a login dialog prompt each time you request the protected page (see Figure 4).
LVL 80

Expert Comment

by:David Johnson, CD, MVP
ID: 39887883
in the website are you set for windows authentication or forms authentication? you also have to setup asp website authentication
LVL 16

Author Comment

by:Vikram Singh Saini
ID: 39888542
First of all thanks to both of experts for answering to neglected question.


Yes! You are right and the excerpt from link speaks truth.

@David Johnson

Yes! I had set for Windows authentication both by IIS and in web.config too.

To both experts

Is there any way that I can get logged in user name from request without using Window authentication?
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

LVL 96

Expert Comment

by:Bob Learned
ID: 39888969
If you have Windows Authentication working correctly, then the identity shouldn't be null.  I believe that the problem is that the identity is null, so it is asking you to log in.
LVL 16

Accepted Solution

Vikram Singh Saini earned 0 total points
ID: 39925482
As I asked,

I want to allow access to specific controller for specific users with Admin role using their logged in credentials (without asking them for their credentials with prompt again).

So I was able to formulate solution for same by myself. Here is the link Window Authentication not working

Hope this will help someone with same issue.
LVL 16

Author Closing Comment

by:Vikram Singh Saini
ID: 39933738
I was able to fix the concerned problem by that solution.

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

860 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question