Mono webservice and basic authentication - c#

I'm trying to add basic authenthication to my webservice. I followed steps from this article and ended up with this in my web.config file:
<configuration>
<httpModules>
<add name="BasicAuthenticationModule"
type="Mono.Http.Modules.BasicAuthenticationModule, Mono.Http, Version=2.0.0.0, PublicKeyToken=0738eb9f132ed756"/>
</httpModules>
<appSettings>
<add key="Authentication" value="Basic" />
<add key="Basic.Users" value="/home/vadmin/Projects/TestService/TestService/users.xml" />
<add key="Basic.Realm" value="My Realm" />
</appSettings>
</configuration>
My users.xml looks like this:
<?xml version="1.0" encoding="utf-8"?>
<users>
<user name="adrian" password="adrian">
<role name="user" />
</user>
</users>
When I run xsp2 and then go to
http://localhost:8080/TestService.asmx
user and password prompt appears. But after I enter correct user and password it asks me again and again. I'm pretty sure that path to users.xml file is correct, tried running xsp2 with --verbose options hoping for some error messages with no luck.
Can anyone help me debug this situation?

If you specify a path starting with / in config file, this will be interpreted not as a root directory of your filesystem, but as a root directory of your website - i.e. /home/vadmin/Projects/TestService/TestService.
So the path starting with / should be relative to website root folder - in your case this will be "/users.xml" if users.xml file is in project folder.

Related

web.release.config transform in web.config

Currently, in my web.config file I have
<configuration>
<general path="c:\abc\" />
</configuration>
I want to change c: to d: when I publish the release version.
How do I do this in a transform?
The <general> section is much much bigger so I don't want to rewrite then entire thing, just that one attribute. Can anyone help?
Update: I created the following web.release.config:
<?xml version="1.0" encoding="utf-8"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<system.web>
<compilation xdt:Transform="RemoveAttributes(debug)" />
</system.web>
<General dataFilePath="D:\Data" xdt:Transform="SetAttributes" xdt:Locator="Match(dataFilePath)" />
<AuditManagement auditPath="D:\Audit" xdt:Transform="SetAttributes" xdt:Locator="Match(auditPath)" />
</configuration>
This had no effect on the final web.config. It still shows "C:\" where I would want "D:\"
You can try adding these attributes to the Web.Release.config:
xdt:Transform="SetAttributes" xdt:Locator="Match(path)"
so your final result should be:
<configuration>
<general path="d:\abc\" xdt:Transform="SetAttributes" xdt:Locator="Match(path)"/>
</configuration>
I would recommend you to use transformation
First you have to create the different enviroments for debug or release, and if you want you can add more.
This tutorial is well explained and tested by me:
http://deanhume.com/home/blogpost/working-with-multiple-web-config-files/4100
And here is the official documentation:
https://msdn.microsoft.com/en-us/library/dd465326%28v=vs.110%29.aspx?f=255&MSPPError=-2147217396
as it is explained in the previous your configuration for the web.config will be:
<configuration>
<general path="d:\abc\" xdt:Transform="SetAttributes" xdt:Locator="Match(path)"/>
</configuration>
and then you will have to define the correct path in the Debug and Realease configs, once it's finished you will run the app with one of the configurations you set.

Reading settings from app.config in .net 4.5

I've added a reference to System.Configuration. I've created App1.config in my project and populated it with the following code:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="ResistanceA" value="0.04"/>
<add key="ResistanceB" value="0.04"/>
<add key="ResistanceC" value="0.01"/>
<add key="TempBattLow" value="40"/>
<add key="TempBattHigh" value="45"/>
<add key="TempLoad" value="40"/>
</appSettings>
</configuration>
Then I try to read the values using the following code,
using System.Configuration;
string str = ConfigurationManager.AppSettings.Get("ResistanceA");
However I do not get the data. Any idea what I am doing wrong? Thanks.
Make sure the (app name here).config file actually appears in the same folder as your (app name here).exe file. Being that you called it App1.config, I'm guessing that you have more than one.
Visual Studio renames App.Config to the actual (app name here).config file during a build, not App1.config.

Get winform Webbrowsercontrol Source from app config file

Can someone please show me how to get winforms Webbrowsercontrol source from appconfig file ?.
I tried with following but it's not working
webBrowser2.Navigate = ConfigurationManager.AppSettings["dateandtime"];
and this is my how app config file look like
<?xml version="1.0"?>
<configuration>
<configSections>
</configSections>
<appSettings>
<add key="serverip" value="127.0.0.1" />
<add key="dbport" value="3306" />
<add key="defdatabase" value="waq115" />
<add key="dateandtime" value="http://free.timeanddate.com/clock/i4daxch9/n77/fs18/fcfff/tc212426/pc212426" />
</appSettings>
<startup><supportedRuntime version="v2.0.50727"/></startup>
</configuration>
Navigate() is a method not a variable, So the following line of code will not compile,
webBrowser2.Navigate = ConfigurationManager.AppSettings["dateandtime"];
You have to read the URL from the application configuration file and pass it as an argument to Navigate("URL") method as follows.
webBrowser1.Navigate(ConfigurationManager.AppSettings["dateandtime"]);

How to avoid commenting (out) <configuration> sections in app.config for specific deployment?

Note:
I've searched for this on Google and didn't directly find anything related to WinForms. The suggested questions while typing this question didn't apply to my situation.
I have a WinForms (.NET 3.5) application that can be published/deployed to three different locations: development, test and production. Each deployment type has its own specific settings, for example: connectionString, title(s), webservice address, directories/files to read or other settings.
The current situation in the app.config is as following:
<!-- dev-->
<configuration>
<configSections>...</configSections>
<appSettings>
<add key="Deployment" value="dev" />
<add key="SourceDir" value="\\server\foo\dev" />
</appSettings>
...
</configuration>
<!-- test -->
<configuration>
<configSections>...</configSections>
<appSettings>
<add key="Deployment" value="test" />
<add key="SourceDir" value="\\server\foo\test" />
</appSettings>
...
</configuration>
<!-- prod -->
<configuration>
<configSections>...</configSections>
<appSettings>
<add key="Deployment" value="prod" />
<add key="SourceDir" value="\\server\foo\prod" />
</appSettings>
...
</configuration>
And everytime the app needs to be published/deployed to a certain location, the other two are commented out. So if I build a DEV-release, I comment out the PROD and TEST sections. When publishing for production, ... you get the idea.
This is a useless time-consuming work. My question is: is there a way to avoid this? A way that I still have the separate deployment-specific configuration, but that I don't need to comment (out) the needed sections.

Visual Studio Express 2013 WPF warning: "The 'configuration' element is not defined" [duplicate]

I'm doing some work in Visual Studio 2012 Express Edition. I have added an App.config XML file as follows:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
</configuration>
The first thing that happens is a warning comes up that says "The 'configuration' element is not declared". Does anyone know why this is happening? It looks like elements can not be declared inside of until this is resolved.
Thanks!
This is the entire XML:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<appSettings>
<add key="Version" value="779" />
<add key="TimeOut" value="60000" />
<add key="LogFileName" value="Log.txt" />
<!-- your Developer Id with eBay -->
<add key="Environment.DevId" value="" />
<!-- your Application Id with eBay -->
<add key="Environment.AppId" value="" />
<!-- your Application Certificate with eBay -->
<add key="Environment.CertId" value="" />
<!-- API Server URL -->
<!-- For production site use: https://api.ebay.com/wsapi -->
<!-- For Sandbox use: https://api.sandbox.ebay.com/wsapi -->
<add key="Environment.ApiServerUrl" value="https://api.sandbox.ebay.com/wsapi" />
<!-- EPS Server URL -->
<!-- For production site use: https://api.ebay.com/ws/api.dll"/-->
<add key="Environment.EpsServerUrl" value="https://api.sandbox.ebay.com/ws/api.dll" />
<!-- eBay Signin URL -->
<!-- For production site use: https://signin.ebay.com/ws/eBayISAPI.dll?SignIn -->
<!-- https://signin.sandbox.ebay.com/ws/eBayISAPI.dll?SignIn -->
<add key="Environment.SignInUrl" value="https://signin.sandbox.ebay.com/ws/eBayISAPI.dll?SignIn" />
<!-- ViewItem URL -->
<!-- For production site use: http://cgi.ebay.com/ws/eBayISAPI.dll?ViewItem&item={0} -->
<add key="Environment.ViewItemUrl" value="http://cgi.sandbox.ebay.com/ws/eBayISAPI.dll?ViewItem&item={0}" />
<!-- token is for both API server and EPS server -->
<add key="UserAccount.ApiToken" value="" />
<!-- eBay site ID -->
<add key="UserAccount.eBayUserSiteId" value="0" />
<add key="logexception" value="true"/>
<add key="logmessages" value="true"/>
<add key="logsdkmessages" value="true"/>
<add key="logsdk" value="true"/>
<add key="logfile" value="Log.txt"/>
<!-- Rule Name-->
<add key="RuName" value=""/>
<!-- Set this if you access eBay API server behind a proxy server-->
<add key="Proxy.Host" value =""/>
<add key="Proxy.Port" value =""/>
<!-- set proxy server username/password if necessary-->
<add key="Proxy.Username" value=""/>
<add key="Proxy.Password" value=""/>
Go to XML menu (visual studio top menu item) choose schemas and find for DotNetConfig.xsd and choose Use this schema.
Your problem will resolve for sure
<configuration xmlns="schema URL">
<!-- configuration settings -->
</configuration>
do changes,like above & try
I had the same issue. It is not an error, it is simply a warning; so your application should still compile. I used the following simple config file and the warning is still produced.
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime
version="v4.0"sku=".NETFramework,
Version=v4.5"/>
</startup>
</configuration>
It is an issue that has been raised on the MSDN website, but it does not seem to have been satisfactorily resolved. See link below:
http://social.msdn.microsoft.com/Forums/en-US/Vsexpressvcs/thread/18a1074f-668f-4fe3-a8d9-4440db797439
I had to
-> Go to XML menu (visual studio top menu item) choose schemas and select DotNetConfig.xsd AND RazorCustomSchema.xsd AND EntityFrameworkConfig_6_1_0.xsd
I just had this warning popup inside an autogenerated xml file while working on a xaml project.
Using Debug->Clean Solution and Debug->Rebuild Solution fixed it. Might want to try that before getting fancy with the schemas.
Visual Studio 2013 Express Edition is missing the DotNetConfig.xsd (https://connect.microsoft.com/VisualStudio/feedback/details/817322/dotnetconfig-xsd-files-not-present-in-vs-2013-express-for-desktop).
So to get rid of the warning in VS 2013 Express:
get a copy of DotNetConfig.xsd from another system or from the web (I used https://gist.github.com/eed3si9n/5dd7dd98ad2b3f668928b23477de35a3)
download to C:\Program Files (x86)\Microsoft Visual Studio 12.0\Xml\Schemas
add the schema following Ramakrishna's answer
The warning should be gone.
Choose use this schema. DotNetConfig.xsd
XLM Menu..... Visual Studio
Works perfectly.
I was having less space on my drive which might have resulted in incomplete loading of my application solution. This "the-configuration-element-is-not-declared" problem got solved after i created some space on my drive.
I also got the same warning. After thinking about for some time I realized my error working with SQL (MS SQL).
Warning: the 'configuration' element is not declared
Using C#
App.Config code:
<connectionStrings>
<add name="dbx" connectionString="Data Source=ServerNameHere;Initial Catalog=DatabaseNameHere;Integrated Security=True" providerName="System.Data.SqlClient"/>
</connectionStrings>
*this calls out the database name in the connectionStrings, when I plugged in my SQL code as a practice I always use the database name, schema, then table. This practice didn't carry over well in Visual Studio as I am a beginner. I removed the db name from my SQL syntax and only called from the schema, data table. This resolved the issue for me.
Form.CS:
using (SqlCommand cmd = new SqlCommand("SELECT * FROM [DatabaseName].[Schema].[TableName] WHERE [MEPeriod] = '2020-06-01'", con))
Updated to:
using (SqlCommand cmd = new SqlCommand("SELECT * FROM [Schema].[TableName] WHERE [MEPeriod] = '2020-06-01'", con))
This worked for me, I hope this is found as useful.

Categories