How to set a username and password for browses a URL?

WindowsGeek 21 Reputation points
2021-09-29T10:03:18.007+00:00

Hello,
How can I set a username and password for a specific URL like "https://example.com/login"? When someone browses that address then he\she must provide a username and password to visit that address.

Thank you.

Internet Information Services
0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. Bruce Zhang-MSFT 3,736 Reputation points
    2021-09-30T02:39:07.467+00:00

    Hi @WindowsGeek ,

    You have two ways to achieve this funtion.

    First, you can set it in application via code. Assuming that you use asp.net application, you can use identity to manage users, passwords, profile data, roles, claims, tokens, email confirmation, and more. It will ask users to enter their password and username in any URL you want to set.

      [HttpPost]  
        [AllowAnonymous]  
        [ValidateAntiForgeryToken]  
        public async Task<ActionResult> Register(RegisterViewModel model)  
        {  
            if (ModelState.IsValid)  
            {  
                var user = new ApplicationUser() { UserName = model.UserName };  
                var result = await UserManager.CreateAsync(user, model.Password);  
                if (result.Succeeded)  
                {  
                    await SignInAsync(user, isPersistent: false);  
                    return RedirectToAction("Index", "Home");  
                }  
                else  
                {  
                    AddErrors(result);  
                }  
            }  
          
            // If we got this far, something failed, redisplay form  
            return View(model);  
        }  
    

    You can combine it with authentication filter to ask for user credentials and authorization filter to manage user premission in any Action. The advantage of using this method is that it stores user data in the database, and you can customize the number of users and the personal information that users need to fill in.

    Second, you can achieve it in IIS manager. Deploy the application on IIS and find the login file. Then switch to feature view. Click authentication module and disable anonymous authentication, enable any other authentication. It is easy to set and don't need to write code. The disadvantage of it is that you cannot customiza any other user information when using windows authentication. It asks for account that exist in user group of windows server. You need to add or delete users manually on windows server.
    136464-3.jpg


    If the answer is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our  documentation  to enable e-mail notifications if you want to receive the related email notification for this thread.

    Best regards,
    Bruce Zhang

    0 comments No comments

  2. WindowsGeek 21 Reputation points
    2021-10-02T10:12:58.257+00:00

    Hello,
    How can I find the login file? When I enter "https://example.com/login", then how can I find the location of that page?

    Thank you.


  3. WindowsGeek 21 Reputation points
    2021-10-06T12:45:57.533+00:00

    Hello,
    Thank you so much.
    First of all, I must find the login file? I mean is "login.asp" or "login.aspx".