i use asp .net core version 3.1.
i know that for disabling 8.3 name creation i can set NtfsDisable8dot3NameCreation vaule to 1 on below path.
"HKLM\SYSTEM\CurrentControleSet\Control\FileSystem"
but my problem is that i dont know how i can set this configuration in web.config file.
actualy i want to use web.config XMl code for solving this issue.
and i try below setting in webconfig but get error when run project.
<configuration>
<HKLM>
<SYSTEM>
<CurrentControleSet>
<Control>
<FileSystem>
<add key="NtfsDisable8dot3NameCreation" value="1"/>
</FileSystem>
</Control>
</CurrentControleSet>
</SYSTEM>
</HKLM>
</configuration>
Related
I am using asp.net core 3.1 and receiving values from URL. Its working fine but when I add "+" sign as a part of URL, it gives 404.
Example : localhost:9000/api/get/%2B12/values
+ is a special character. It should ideally be should be URL encoded as %2B.
Turns out it's not really required though (like in the screenshot below) but I still recommend it. (See: URL encoding the space character: + or %20?)
Here's a working example controller:
[ApiController]
public class ExpController : Controller
{
[Route("/api/exp/{arg}/values")]
public IActionResult Test(int arg) =>
Ok($"The arg is: {arg}");
}
Note how the route parameter is a int. For more complex values (other than just 12, +12, -12; eg: 12+12) the route will need to be a string instead.
version above IIS7 will refuse to request the URL contains symbols such as '+' by default. The following modifications are required. You need add the following nodes in web.config:
<system.webServer>
<security>
<requestFiltering allowDoubleEscaping="true"/>
</security>
</system.webServer>
But now the .net core project does not have web.config to configure IIS options. You need to go to the location:
vs project location /.vs/config/applicationhost.config to add the above node.
Note that the .vs folder is a hidden folder and needs to be set visible.
Option 1 :
Mess with config to bypass request validation / allowDoubleEscaping (Asp.Net)
You need to be aware for certain risk/vulnabilirities described here:
https://stackoverflow.com/a/53621095/4798459
.netcore :
Since this issues is related to IIS, not your solution. You need to handle a web.config
Create a new web.config on the root of your project.
Right click, properties, set "Copy to Output Directory" to "Copy Always"
When you publish a .net core app, a "basic web.config" file is created. (For iis)
You need to copy the content of the "basic web.config".
You can find the auto-generated web.config file:
Where your app is already published (local server?)
You can also publish your api temporarly to a random path on your PC, see details here https://docs.devexpress.com/OfficeFileAPI/401445/dotnet-core-support/publish-net-core-application)
The web.config should like so, i added the tag with a a commentt
<configuration>
<location path="." inheritInChildApplications="false">
<system.webServer>
<!-- XML node <security> is added to allow allowDoubleEscaping and add support for + paremeter in a route. Risk:https://stackoverflow.com/a/53621095/4798459 -->
<security>
<requestFiltering allowDoubleEscaping="true"></requestFiltering>
</security>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
</handlers>
<aspNetCore processPath="dotnet" arguments="[.\SolutionName.Namespace.dll]" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="inprocess" />
</system.webServer>
</location>
</configuration>
Make sure that the step 2 is done before publishing your app otherwise it wont work.
Not tested with iisexpress
Option 2
Change pramater type in the api. Intead of being on the route, use a queryString instead
Option 3
Custom solution for request filtetring /routing, which i don't have any example, and seems a bit "over the top".
Option 4, to avoid:
Use an other solution for encoding / decoding special caracter (I have not tried)
https://stackoverflow.com/a/55637235/4798459
I am running IIS under Windows Server 2016 and I'm trying to run an ASP.Net core 3.1 application but I can't get past this error:
500.19 error
(The language in the picture is Hungarian, but it contains no useful information whatsoever, just an example)
Here is my web.config
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<location path="." inheritInChildApplications="false">
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
</handlers>
<aspNetCore processPath=".\Minibizz.Routing.Web.exe" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="inprocess" />
</system.webServer>
</location>
</configuration>
What am I missing?
P.S.: The web.config was created by Visual Studio 2019.
The reason behind the issue:
That error message goes on to say what exactly is bad about your configuration file, hence you should refer the “Config Error” and “Config Source” sections. This problem occurs because of the ApplicationHost.config file or the Web.config file contains a malformed or unsupported XML element.
if you are using url rewrite rule then install url rewrite Extention of iis. Enable ANCM logging, ie. set stdoutLogEnabled="true" stdoutLogFile=".\logs\stdout\" (I think the path needs to end by a backslash), then run the web app and see if something gets logged into the stdout folder. Verify that the log directory exists at the path referenced by the web config. If it does not, create it. The path shown in your config would place the "logs" directory in the root folder of the deployed site. Verify that the application pool has to write access to the logs directory.
Make sure you installed the .net bundle.check that you installed below iis feature:
You may also need to verify that the path to the dotnet executable exists in the deployment machine's environment variables. To check this, first find the path where dotnet.exe is installed. It is generally located in either C:\Program Files\dotnet or C:\Program Files (x86)\dotnet. Once you know the path, ensure that the path exists in your Environment Variables.
The web.config content seems to be correct. If you use a clean web.config copy, does the problem persist? If the issue can be solved by replacing web.config with clean configuration content, then the problem is exactly with this web.config. In this case, I suggest you remove parts of the web.config content to narrow down the issue. If the pages show correctly after you remove one section, then the problem is with that section. You need double-check what's wrong with the section and update the correct configuration.
If the problem remains even with clean web.config content, I suggest you access other pages in different folders in your site to see if the problem still exists.
you could refer this below link for how to publish asp.net core site in iis:
https://learn.microsoft.com/en-us/aspnet/core/tutorials/publish-to-iis?view=aspnetcore-3.1&tabs=visual-studio
There are 2 applications pointing to 2 different paths.
1. C:\Windows\Microsoft.NET\Framework\v4.0.30319\Config\web.config
2. C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Config\web.config
I want to keep my connection strings in 1 single file so that both the applications should be able to read the same.
Any idea?
You can try to store your connection strings in external .config file and include it in both web.config files. Here is how to export profile configuration into a dedicated configuration file.
This is web.config:
...
<system.web>
...
<profile configSource="profile.config" />
...
</system.web>
...
This is profile.config:
<profile>
<properties>
<add name="Name" type="String" />
<add name="Age" type="Int32" />
</properties>
</profile>
Make sure you use .config as the extension of your files so they cannot be served to the browser.
See this blog post for details
To use one .config file in multiple applications create a symbolic link to that file in each application folder and reference that link in web config. Use mklink command in elevated command prompt:
cd "c:\YourApplicationDirectoryWhereWebConfigIs"
mklink profile.config "c:\YourSharedConfigFilesDirectory\profile.config"
I've spent half of a day trying to understand why the following fails.
I can add section anywhere but never got it working like that ():
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<mysection />
<system.web>
<compilation debug="false" batch="false" targetFramework="4.0" />
</system.web>
<system.webServer>
<handlers>
</handlers>
</system.webServer>
</configuration>
I think the error related to .NET 4, because when you put section without pre-configuration in applicationHost.config it shows error with gray border saying that config is incorrect. That is what I expect. Then I add section definition and everything seems to work I can edit config from console - this means it is parsed correctly now.
But when I try to reach Application, it gives:
Parser Error Message: Unrecognized configuration section mysection
with a piece of config on yellow background.
Or do I need to write a module to consume that settings ? At the moment I do not have any, just a text in config.
following links will help you understand for this.
http://www.codeproject.com/Articles/32628/ASP-NET-Custom-Web-Configuration-Section
https://web.archive.org/web/20211020133931/https://www.4guysfromrolla.com/articles/032807-1.aspx
Regards,
Old topic but these links are very helpfull:
http://www.iis.net/learn/develop/extending-iis-configuration/configuration-extensibility
http://www.iis.net/learn/develop/extending-iis-configuration/extending-iis-schema-and-accessing-the-custom-sections-using-mwa
Edit (05/25/2016) :
The Details of how to store custom information in applicationHost.config file ... I hope this helps !
Note : These settings wont be visible on IIS Manager. There is a way to do that but thats beyond the scope of this response.
Requirement:
Need to extend the system.applicationHost/sites section of applicationHost.config file to allow a siteowner attribute at the site level. (IIS Does not allow us to do this by default). Nor can you manually edit the applicationHost.config file and add custom tags/attributes.
Steps:
Create a custom schema ( xml ) file under %windir%\system32\inetsrv\config\schema\ . File name: siteExtension_schema.xml
Include the custom elements that you want to eventually save in the applicationHost.config in that xml and save it with a appropriate name. The crucial thing to keep in mind is the sectionSchema tag.So when extending the schema of an existing section, simply create a element and set the name attribute to be the same as an existing section. In the schema file (see below), we have defined a with a name of "system.applicationHost/sites" - this is the same as the sectionSchema name in the default IIS_Schema.xml file in the Schema directory. So in essence you are instructing IIS to add these
<!-- Contents of %windir%\system32\inetsrv\config\schema\siteExtension_schema.xml -->
<configSchema>
<sectionSchema name="system.applicationHost/sites">
<collection addElement="site">
<attribute name="owner" type="string" />
<attribute name="ownerEmail" type="string" />
</collection>
</sectionSchema>
</configSchema>
Test the modifications by adding values for the "owner" and "ownerEmail" attributes that we included in step 2 above and then check the configuration file (applicationHost.config) to see the changes. Simply run the following command (must be elevated as Administrator) from the command line (uses appcmd ) to do so:
C:\> %windir%\system32\inetsrv\appcmd set site "Default Web Site" /owner:"John Contoso" /ownerEmail:"john#contoso.com"
To see if the configuration was applied, run the following command and check the output:
C:\> %windir%\system32\inetsrv\appcmd list site "Default Web Site" /config
<system.applicationHost>
<sites>
...
<site name="Default Web Site" id="1" siteOwner="John Contoso" siteOwnerEmail="john#contoso.com">
...
...
</site>
</sites>
</system.applicationHost>
To Read and Write your settings programmatically thru C# :
//this Will work with the ServerManager.OpenRemote("MyRemoteHostname") method also
using(var mgr = new ServerManager())
{
//Read
Console.WriteLine(mgr.Sites["Default Web Site"].Attributes["owner"].Value ); //Prints "John Contoso"
//Write
mgr.Sites["Default Web Site"].Attributes["owner"].Value = "New Owner";// Sets new value
mgr.CommitChanges(); // commits the changes to applicationHost.Config
}
I made a web.config (full file, it doesn't show XML errors)
<?xml version="1.0"?>
<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
<configSections>
...
<location path="." inheritInChildApplications="false">
<connectionStrings>
<add name="ElmahLog" connectionString="data source=~/App_Data/Error.db" />
<add name="database" connectionString="w" providerName="System.Data.EntityClient"/>
</connectionStrings>
</location>
...
with a transform file (web.Staging.config)
<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<connectionStrings>
<add name="database"
connectionString="c"
providerName="System.Data.EntityClient"
xdt:Transform="SetAttributes" xdt:Locator="Match(name)" />
</connectionStrings>
<system.web>
<compilation xdt:Transform="RemoveAttributes(debug)" />
<customErrors defaultRedirect="error.aspx"
mode="RemoteOnly" xdt:Transform="Replace">
</customErrors>
</system.web>
</configuration>
I am publishing in Staging mode (right click website > Publish > Method: File System ...)
------ Build started: Project: Drawing, Configuration: Staging Any CPU ------
Drawing -> D:\Project\bin\Staging\Drawing.dll
------ Build started: Project: MySystem, Configuration: Staging Any CPU ------
MySystem -> D:\Project\bin\Staging\MySystem.dll
...
But when I look at the web.config in the output folder it isn't changed.
I found the following on the Build log:
D:\Project\Web.Staging.config(3,2): Warning : No element in the source document matches '/configuration'
D:\Project\Web.Staging.config(3,2): Warning : No element in the source document matches '/configuration'
D:\Project\Web.Staging.config(3,2): Warning : No element in the source document matches '/configuration'
Transformed web.config using Web.Staging.config into obj\Staging\TransformWebConfig\transformed\web.config.
What could be the problem? Am I doing this right?
Answering late but perhaps I can save someone a headache. In Visual Studio 2013, there are two places to select configuration for your build and deploy. The Configuration Manager and then again with Publish Web where the third step in the Wizard entitled Settings allows you to select Config you want to use. If you don't select your new configuration it will use the transform for the selected configuration instead of yours.
I found out two things:
You cannot set a namespace on the <configuration> tag (ex: for <location path="." inheritInChildApplications="false">)
You have to watch for the correct hierarchy in the transform file.
Like
<configuration>
<location>
<connectionStrings>
Instead of
<configuration>
<connectionStrings>
Ensure that in the properties of the Web.Config file Build Action is set to Content.
If the build action is set to None, it will not be transformed, even if it is being copied to the output directory.
Make sure to include InsertIfMissing if the section you are trying to add does not already appear in the output.
<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<location>
<system.webServer>
<security xdt:Transform="InsertIfMissing">
<requestFiltering allowDoubleEscaping="true" />
</security>
</system.webServer>
</location>
</configuration>
Don't forget to copy all the other attributes of "configuration" from the original "web.config", as it seems that VS2012 doesn't do it automatically and of course there will be no match...
Answering late as well, but this may help someone.
I realized that if you have two websites in the same solution, when you try to publish one of them the transformation might not work if you have one only configuration for both projects.
One of my websites was always transforming, but the other sometimes was and sometimes wasn't.
For example, I had the configuration "Auto" in the solution, and had web.Auto.config for both websites.
I resolved that by creating a new configuration with a different name - "AutoAdmin" - creating also its web.AutoAdmin.config file for the second project, and when I published it again the transformation finally occurred.
I followed the below steps to fix this issue. Thanks, #michaelhawkins for pointing in the right direction. You need to make sure you change the configuration to release in two places.
And right click on your project and select "Properties". IF not working try selecting x86 in CPU Architecture
#Karthikeyan VK your post resolved my issue. Although I was selecting Production configuration in my publish profile, in configuration manager it was set to dev therefore It didn't transform my settings.
Microsoft needs to fix this bug. Once you pick a configuration in the publishing profile it should automatically update the configuration manager as well.