简体   繁体   中英

How to create working Basic Authentication in C#

I used this tutorial to create a basic authentication for my website:
http://msdn.microsoft.com/en-us/data/gg192997.aspx
I modified the password to admin, however, when I try to access the website in any browser, it always prompts for username and password but never accepts it. If I change the code to return true on

public static bool Authenticate(HttpContext context)

It doesn't change anything. What else should I set?

Make sure that all authentication settings in IIS (for the specific site) are disabled and only Basic Authentication is enabled. Browsers are expected to request a user and password that are always acceptable when they are valid. Sometimes restarting a site and its relative application pool may also help (especially in older versions of windows).

Have in mind that basic authentication is not safe as it passes credentials via a request header in base64 encoding. A good idea is to use ssl - you can get a free one from startssl.com for a live site, or create a self signed one from iis for dev perposes.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM