First I add my package source (test).
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
<add key="test" value="https://mytestpackagesource" />
</packageSources>
</configuration>
When I run dotnet restore I get a 401 (Unauthorized), which is expected. So I add credentials.
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
<add key="test" value="https://mytestpackagesource" />
</packageSources>
<packageSourceCredentials>
<test>
<add key="Username" value="apparently this can be anything when you use a token?" />
<add key="ClearTextPassword" value="my personal access token" />
</test>
</packageSourceCredentials>
</configuration>
And this works. But if I change the token to something invalid or even remove the packageSourceCredentials element completely it still works, which makes me believe my token got stored somewhere else. So my question is where did it get stored and how do I update it?
Related
I'm a bit confused as to how I can specify another .config file in my web.config while retaining parts of the original web config. I want to put my connection strings in another file but when I build the project I get an error about there being multiple appsettings elements.
I have this:
<appSettings file="ConnectionStrings.config">
</appSettings>
then further down, because it's a Crystal Reports application, these settings are specified. I don't want these keys in my connnectionstrings.config file as they're not relevant.
<appSettings>
<add key="CrystalImageCleaner-AutoStart" value="true"/>
<add key="CrystalImageCleaner-Sleep" value="60000"/>
<add key="CrystalImageCleaner-Age" value="120000"/>
</appSettings>
How do I keep my seperate config file and the Crystal settings above, without putting them all in the connectionstrings.config file?
You main configuration file(web.config) should look like this
<?xml version="1.0"?>
<configuration>
<!--other sections-->
<appSettings file="appSettings.config">
<add key="CrystalImageCleaner-AutoStart" value="true"/>
<add key="CrystalImageCleaner-Sleep" value="60000"/>
<add key="CrystalImageCleaner-Age" value="120000"/>
</appSettings>
<!--other sections-->
</configuration>
Further your separate appSettings.config should look like this
<?xml version="1.0" encoding="utf-8"?>
<appSettings>
<add key="YourConnectionStringValue" value="" />
</appSettings>
This is how we have worked in our project.
Try this, maybe!
<appSettings file="ConnectionStrings.config">
<add key="CrystalImageCleaner-AutoStart" value="true"/>
<add key="CrystalImageCleaner-Sleep" value="60000"/>
<add key="CrystalImageCleaner-Age" value="120000"/>
</appSettings>
I have a web.config file that links to a common.config file. common.config is being used by multiple applications. I used the aspnet_regiis.exe, but that only encrypts the web.config file. How can i encrypt the common.config file?
web.config file:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<appSettings file="C:\Users\naem\Documents\common.config" />
<system.web>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5" />
</system.web>
</configuration>
common.config file:
<?xml version="1.0" encoding="utf-8"?>
<appSettings>
<add key="webpages:Version" value="3.0.0.0" />
<add key="webpages:Enabled" value="false" />
<add key="ClientValidationEnabled" value="true" />
<add key="UnobtrusiveJavaScriptEnabled" value="true" />
<add key="myKey" value="This is the Value!!!!"/>
</appSettings>
I don't have the rep to comment on the original post, but this looks like a duplicate of How to encrypt .config file Asp.net
I found workaround to solve this issue. Hope it helps.
Rename your common.config to web.config temporarily.
Add configuration as root element to this file. So your common.config will look like as follows.
<configuration>
<appSettings>
<add key="webpages:Version" value="3.0.0.0" />
<add key="webpages:Enabled" value="false" />
<add key="ClientValidationEnabled" value="true" />
<add key="UnobtrusiveJavaScriptEnabled" value="true" />
<add key="myKey" value="This is the Value!!!!"/>
</appSettings>
</configuration>
Run encrypt command.
aspnet_regiis.exe -pef appSettings "C:\Users\naem\Documents"
Open encrypted file and remove Configuration tags.
Rename file to Common.config
I added the following to my web.config so users can not download my plugins:
<system.webServer>
<security>
<requestFiltering>
<hiddenSegments>
<add segment="Plugins" />
</hiddenSegments>
</requestFiltering>
</security>
</system.webServer>
Now I have the problem that not only domain.com/Plugins/MyPlugin.dll is blocked, but also domain.com/Scripts/ckeditor/plugins/ckplugin.js.
Is there a way to configure a hiddenSegment to only affect the root directory?
I solved this via a web.config inside my plugins folder, where I block *.dll files from being downloaded:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<handlers>
<add name="Plugins*.dll_*" path="*.dll" verb="*" type="System.Web.HttpForbiddenHandler" />
<add name="Plugins*.pdb_*" path="*.pdb" verb="*" type="System.Web.HttpForbiddenHandler" />
</handlers>
</system.webServer>
</configuration>
I've made some additional modifications on top of Christoph's answer to suite my use case, but I will leave this here for future references.
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<!-- Make sure this directory cannot be served. -->
<location path="Plugins"> <!-- Change this to your path -->
<system.webServer>
<handlers>
<add name="DisallowServe" path="*.*" verb="*" type="System.Web.HttpNotFoundHandler" /> <!-- Return 404 instead of 403 -->
</handlers>
</system.webServer>
</location>
</configuration>
I'm creating a NuGet package and want it to update the web projects Web.Config file with certain settings. I am using the web.config.transform to edit the web.config file of an application. It's working well when I simply add appSettings - like so:
<configuration>
<appSettings>
<add key="WebPToolFolder" value ="~/Tools"/>
<add key="ImagesFolder" value ="~/Content/themes/base/images"/>
</appSettings>
</configuration>
However, if I try an add to the staticContent it doesn't seem to alter the tags. For example, here is the web.config.transform file:
<configuration>
<appSettings>
<add key="WebPToolFolder" value ="~/Tools"/>
<add key="ImagesFolder" value ="~/Content/themes/base/images"/>
</appSettings>
<system.webServer>
<staticContent>
<mimeMap fileExtension=".webp" mimeType="image/webp" />
</staticContent>
</system.webServer>
</configuration>
It updates the appSettings, but not the staticContent tags - any ideas?
Old question but if anyone lands on it the following should work:
In your case to add/update the staticContent element:
It's an alternative solution, so you won't use the .transform file, but rather the web.config.install.xdt (and web.config.uninstall.xdt) which I find better:
<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<!-- some other elements -->
<staticContent xdt:Transform="InsertIfMissing">
<mimeMap fileExtension=".webp" mimeType="image/webp" xdt:Locator="Match(fileExtension)" xdt:Transform="InsertIfMissing" />
</staticContent>
<!-- some other elements -->
</configuration>
This way you don't need to do any pre-update preperations, just upgrade the package.
Check this post for XDT support from Nuget 2.6 onwards.
You need to put an empty <staticContent></staticContent> in your web.config and then use the xdt:Transform="Insert" on the element like this:
Your web.config:
<configuration>
<appSettings>
<add key="WebPToolFolder" value ="~/Tools"/>
<add key="ImagesFolder" value ="~/Content/themes/base/images"/>
</appSettings>
<system.webServer>
<staticContent>
</staticContent>
<system.webServer>
</configuration>
And then you can insert a value in your transform file like this:
<system.webServer>
<staticContent>
<mimeMap fileExtension=".webp" mimeType="image/webp" xdt:Transform="Insert"/>
</staticContent>
</system.webServer>
Took me a while to find out. Hope this helps.
Have you tried adding an xdt:Transform="Replace" attribute to the tags you want to update?
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<appSettings>
<add key="WebPToolFolder" value ="~/Tools" xdt:Transform="Replace"/>
<add key="ImagesFolder" value ="~/Content/themes/base/images" xdt:Transform="Replace"/>
</appSettings>
<system.webServer>
<staticContent>
<mimeMap fileExtension=".webp" mimeType="image/webp" xdt:Transform="Replace"/>
</staticContent>
</system.webServer>
</configuration>
There's some good Microsoft documentation here
If you post the initial markup and what you want it to look like maybe we could help a bit more :)
I have a website which has been running on IIS7 for about 2 months. We have the default documents set up to load a default.asp page when users go to the domain with no page. Suddenly this morning, I am getting errors and the default document will not load. If I type the default.asp, the file loads just fine.
Error Info:
Module: DefaultDocumentModule
Notification: ExecuteRequestHandler
Handler: StaticFile
Error Code: 0x80070002
here is a section from my applicationhost.config:
<system.webServer>
<asp>
<cache diskTemplateCacheDirectory="%SystemDrive%\inetpub\temp\ASP Compiled Templates" />
</asp>
<defaultDocument enabled="true">
<files>
<clear />
<add value="Default.asp" />
<add value="Default.htm" />
<add value="index.htm" />
<add value="index.html" />
<add value="iisstart.htm" />
</files>
</defaultDocument>
<directoryBrowse enabled="false" />
<globalModules>
<add name="UriCacheModule" image="%windir%\System32\inetsrv\cachuri.dll" />
<add name="FileCacheModule" image="%windir%\System32\inetsrv\cachfile.dll" />
<add name="TokenCacheModule" image="%windir%\System32\inetsrv\cachtokn.dll" />
<add name="HttpCacheModule" image="%windir%\System32\inetsrv\cachhttp.dll" />
<add name="StaticCompressionModule" image="%windir%\System32\inetsrv\compstat.dll" />
<add name="DefaultDocumentModule" image="%windir%\System32\inetsrv\defdoc.dll" />
<add name="DirectoryListingModule" image="%windir%\System32\inetsrv\dirlist.dll" />
<add name="ProtocolSupportModule" image="%windir%\System32\inetsrv\protsup.dll" />
<add name="HttpRedirectionModule" image="%windir%\System32\inetsrv\redirect.dll" />
<add name="ServerSideIncludeModule" image="%windir%\System32\inetsrv\iis_ssi.dll" />
<add name="StaticFileModule" image="%windir%\System32\inetsrv\static.dll" />
<add name="AnonymousAuthenticationModule" image="%windir%\System32\inetsrv\authanon.dll" />
<add name="RequestFilteringModule" image="%windir%\System32\inetsrv\modrqflt.dll" />
<add name="CustomErrorModule" image="%windir%\System32\inetsrv\custerr.dll" />
<add name="HttpLoggingModule" image="%windir%\System32\inetsrv\loghttp.dll" />
<add name="RequestMonitorModule" image="%windir%\System32\inetsrv\iisreqs.dll" />
<add name="IsapiModule" image="%windir%\System32\inetsrv\isapi.dll" />
<add name="IsapiFilterModule" image="%windir%\System32\inetsrv\filter.dll" />
<add name="CgiModule" image="%windir%\System32\inetsrv\cgi.dll" />
<add name="FastCgiModule" image="%windir%\System32\inetsrv\iisfcgi.dll" />
<add name="ManagedEngine" image="%windir%\Microsoft.NET\Framework\v2.0.50727\webengine.dll" preCondition="integratedMode,runtimeVersionv2.0,bitness32" />
<add name="ConfigurationValidationModule" image="%windir%\System32\inetsrv\validcfg.dll" />
<add name="ManagedEngine64" image="%windir%\Microsoft.NET\Framework64\v2.0.50727\webengine.dll" preCondition="integratedMode,runtimeVersionv2.0,bitness64" />
<add name="RewriteModule" image="%SystemRoot%\system32\inetsrv\rewrite.dll" />
<add name="ManagedEngineV4.0_32bit" image="C:\Windows\Microsoft.NET\Framework\v4.0.30319\webengine4.dll" preCondition="integratedMode,runtimeVersionv4.0,bitness32" />
<add name="ManagedEngineV4.0_64bit" image="C:\Windows\Microsoft.NET\Framework64\v4.0.30319\webengine4.dll" preCondition="integratedMode,runtimeVersionv4.0,bitness64" />
<add name="WebDAVModule" image="%SystemRoot%\system32\inetsrv\webdav.dll" />
<add name="WindowsAuthenticationModule" image="%windir%\System32\inetsrv\authsspi.dll" />
</globalModules>
I have also verified that the modules physically exist on disk. I am not aware of any changes on this server, and the default document has definitely been working up till yesterday. Server is Windows Server 2008 x64 with IIS 7.0.
I've recycled the app pool, booted the server, removed and reentered the default documents. the error looks like it cant find the default document module..
What else can I try?
My coworker and I have been chasing this all morning and someone on IRC pointed us to the resolution. Turns out that IIS was having trouble with the default document b/c the website root folder had gotten marked as Hidden. Apparently, when the folder is Hidden, the default document module cannot find it and you get the ERROR_FILE_NOT_FOUND shown above.
We verified this behavior on a Dev server by setting the web root folder to Hidden and sure enough got the same error for the default document. Removed the Hidden attribute and the default document loads correctly.
I have seen a lot of questions about this today, and no one has posted an answer that fit our problem. I want to say thanks to whoever that was on IRC! And hopefully this will help others to post it here.