简体   繁体   中英

It is possible to give different Google API Key in ASP.NET Google maps Application?

  I am using googlemaps.subgurim.net in my application,it is possible to set different GOOGLE API KEY to different users based on their logins.
              web.config:        
            <add key="googlemaps.subgurim.net" value="xxxxxxxxx"/>       
            .aspx:        
            <cc1:GMap ID="GMap1" runat="server" Height="805px" Width="800px" />       
            .aspx.cs:        
            string sMapKey = ConfigurationManager.AppSettings["googlemaps.subgurim.net"];
            GeoCode objAddress = new GeoCode();          
            objAddress=Map.geoCodeRequest(newGLatLng(Convert.ToDouble(status.Rows[0][0]),Convert.ToDouble(status.Rows[0][1])), sMapKey);
                                    StringBuilder sb = new StringBuilder();
                                    if (objAddress.valid)
                                    {
                                        sb.Append(objAddress.Placemark.address.ToString());
                                        lbladd.Text = sb.ToString();
                                    }    

I am using googlemaps.subgurim.net in my application,it is possible to set different GOOGLE API KEY to different users based on their logins.

Yes, it is. You will need to persist their API Key in their user record eg in the Database then in your Api script just switch in the variable

Web Forms

<script type="text/javascript"
  src="https://maps.googleapis.com/maps/api/js?key=<%=User.ApiKey%>&sensor=SET_TO_TRUE_OR_FALSE">
</script>

MVC

<script type="text/javascript"
  src="https://maps.googleapis.com/maps/api/js?key=@Model.UserApiKey&sensor=SET_TO_TRUE_OR_FALSE">
</script>

Might be worth in your Getter that if their APi key is null, then switch in your default.

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