ASP.Net MVC Web app - I have the following code in my Web.config file:
<configuration> <configSections> <!-- For more information on Entity Framework configuration, visit http://www.contoso.com --> <section name="entityFramework" type="words, EntityFramework, Version=numbers, Culture=more words" /> </configSections> <appSettings> <add key="x-coord" value="x1,x2,x3" /> <add key="y-coord" value="y1,y2,y3" /> </appSettings> </configuration> And this is a conditional inside the method that uses the <appSettings> key-values:
if (ModelState.IsValid && ((ConfigurationManager.AppSettings["x-coord"].Contains(postModel.xCoordinate.ToLower()) & ConfigurationManager.AppSettings["y-coord"].Contains(postModel.yCoordinate.ToLower)))) { return View(postModel); } The issue is that as this code is written, as long as any of the x-coord values are passed, and any of the y-coord values are passed, the conditional will evaluate to true.
I need to have the code function such that x1 and y1 must be passed to evaluate to true, OR, x2 and y2, OR, x3 and y3, such that these are true key-value pairs, as opposed to just two Lists.
I believe this all comes down to the Contains method, which is what is allowing any pair of x and y to be allowed. I just don't know how to go about enforcing strict pairing as outlined above.
&&rather than&. b) Strip the first character off the x and y co-ordinate and compare them. c) Don't useContainslike you are -xwill be found even though it has no number.String.Splitthe config setting into an array and then runContains/IndexOfon that.