ASP.NET Core项目中Bing Maps凭证无效问题求助
Let's walk through the most likely fixes for your Bing Maps authentication error:
1. Remove Duplicate Credential Setup
Looking at your code, you're passing the API key twice—once in the script URL and once in the credentials property of the map options. Modern Bing Maps implementations only require the key in the script URL, and having both can cause conflicts.
Update your GetMap function to remove the redundant credentials line:
function GetMap() { var map = new Microsoft.Maps.Map('#myMap', { center: new Microsoft.Maps.Location(51.50632, -0.12714), mapTypeId: Microsoft.Maps.MapTypeId.aerial, zoom: 10 }); }
And confirm the script URL uses your actual key (replace [my API key] with the full, unmodified key, no brackets):
<script type='text/javascript' src='https://www.bing.com/api/maps/mapcontrol?callback=GetMap&key=YOUR_FULL_API_KEY' async defer></script>
2. Verify Your API Key's Configuration
- Check Key Type: When creating keys in the Bing Maps Portal, ensure you selected the Web application type. Keys made for mobile or other platforms won't work for web apps.
- IP Restrictions: If you enabled IP restrictions on your key, make sure the server/host running your ASP.NET app is in the allowed IP list. For local testing, either add your local IP or temporarily disable restrictions to rule this out.
- Key Status: Double-check that the key is marked as "Enabled" in the portal—sometimes keys get disabled accidentally during setup.
3. Clear Browser Cache
Browser caching can sometimes hold onto old, invalid key references. Test your page in incognito/private mode or clear your browser's cache and cookies to eliminate this possibility.
4. Check for Typos or Copy-Paste Errors
It sounds simple, but even a single missing character or extra space in your API key will trigger this error. Re-copy the key directly from the Bing Maps Portal and paste it into your code—avoid manually typing it.
5. Test with a Fresh Key
If all else fails, create a brand new key in the portal (make sure to select the Web type again) and test with that. Occasionally, keys can have hidden issues during creation that aren't visible in the portal.
内容的提问来源于stack exchange,提问作者Daniel Ninchev

