Master page error on adding? - asp.net

I a trying to add New Master Page in fresh project throw 'Add new Items" while adding i have this Error "Data at the root level is invalid. Line 1. Position 1"
How to solve this please ?
my web.config
<?xml version="1.0"?>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<system.web>
<compilation debug="false" targetFramework="4.0" />
</system.web>
</configuration>

Okay, I can reproduce your error in my environment.
The problem is occured if you have an invalid XML file in your project. Probably the web.config.
Can you confirm that the XML files in your project is well formed? Try to open the XML file using IE and ensuring that there are no errors.

Related

Cannot open/create ASP.NET applications in Visual Studio 2019

I'm having trouble opening my projects in Visual Studio. I get the following error and the project does not load.
Creation of virtual directory failed with the following error: Filename: C:\Windows\Microsoft.NET\Framework\v4.0.30319\Config\web.config
Line number: 24
Error: The configuration section 'fulltrustassemblies' cannot be read because it is missing a section declaration.
I tried creating a new ASP.NET webform application with target framework 4.7.2 (same as the ones of the project that does not load) and get the same issue.
Did you try if adding the section to the file solve the problem?
<configuration>
<system.webServer>
<system.web>
<fullTrustAssemblies>
<clear/>
</fullTrustAssemblies>
</system.web>
</system.webServer>
</configuration>
In the respective web.config file, you need to removed following element:
<fullTrustAssemblies>
....
</fullTrustAssemblies>
<partialTrustVisibleAssemblies />

ASP.Net Website - publishing doesn't move all files

When publishing my ASP.Net Website (not a Web Application), the publisher does not include the Web.ConnectionStrings.config file that is next to the web.config. This is required since my web config looks like this:
<connectionStrings configSource="Web.ConnectionStrings.config"/>
How can I get a File System Publish to include files that Visual Studio seems to be ignoring. Please note that this is a website created using [File] > [New Website] in Visual Studio, not a [File] > [New Project] ASP.Net site so Content=Include will not work.
Steps to reproduce:
In Visual Studio: File > New > Website..
Create the Web.ConnectionStrings.config xml document (see ConnectionStrings.config code below).
In the web config link up the Web.ConnectionStrings.config file to the Web.Config file (see Web.config code below)
Publish the website to a folder on your file system, the Web.ConnectionStrings.config doesn't move with the rest of the files.
Web.config:
<configuration>
<connectionStrings configSource="Web.ConnectionStrings.config"/>
..
Web.ConnectionStrings.config:
<?xml version="1.0" encoding="utf-8" ?>
<connectionStrings>
<add name="connString" connectionString="yourConnectionstringhere"/>
</connectionStrings>
The way you publish the website is OK.
But the name of the file into which the connectionstrings get stored must not start with the prefix web., just call it connectionstrings.config instead.
In web.config you put:
<configuration>
<connectionStrings configSource="connectionStrings.config"/>
In the renamed file connectionstrings.config you place:
<?xml version="1.0" encoding="utf-8" ?>
<connectionStrings>
<add name="connString" connectionString="yourConnectionstringhere"/>
</connectionStrings>
I think this article will help
https://learn.microsoft.com/en-us/aspnet/web-forms/overview/deployment/visual-studio-web-deployment/deploying-extra-files
Basically you edit the picture .pubxml file to tell it to include additional files during deployment

Server Error in '/' Application. This type of page is not served

I have an host where I hosted a webpage with .cshtml extension. My host is arvixe.com that provides ASP and .NET hosting but when I try to load my web page I get this error message.
Server Error in '/' Application.
This type of page is not served.
Description: The type of page you have requested is not served because it has been explicitly forbidden. The extension '.cshtml' may be incorrect. Please review the URL below and make sure that it is spelled correctly.
Requested URL: /samples/WoT/Default.cshtml
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.276
I read something does I have to write something in my web.config file to make it work
like this
<compilation>
<assemblies>
<add assembly="System.Web.WebPages.Razor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
</assemblies>
<buildProviders>
<add extension=".cshtml" type="System.Web.WebPages.Razor.RazorBuildProvider, System.Web.WebPages.Razor"/>
</buildProviders>
</compilation>
But I tried everything, paste it in on different lines, nothing worked. What do I miss or do wrong?
I believe you are not making using the MVC feature and trying to load just the razor view outside views or custom Area folders.
Then you need to enable webpages key in Web.config which is disabled by default in .Net 4.0
<add key="webpages:Enabled" value="true" />
<appSettings>
<add key="webpages:Enabled" value="true" />
Repairing this in Windows 10 Pro using IIS 10 was a nightmare, it took two days but I was finally able to achieve the desired results using the following procedure:
Open your web site in Visual Studio. The way you do this is to go to File > New > Web Site and then select ASP.Net Empty Web Site AND before you click OK change the location to your project location. In my case I had my project in C:\inetpub\wwwroot\AspNet\Projects\Test
Open internet information services manager (click the "cortana" search and type IIS, it should show up as long as you have it installed). Locate your project folder under the ServerName > Sites > Default Web Site > ... , right click on it and click the "Convert to web Application" button. Accepting the defaults at the prompt by clicking OK should be sufficient in most cases.
Use the following Web.Config file, or something similar. NuGet may overwrite some settings but this isn't a big problem.
<?xml version="1.0" encoding="utf-8"?>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=301879
-->
<configuration>
<appSettings>
<add key="webPages:Version" value="3.0.0"/>
<add key="webpages:Enabled" value="true"/>
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.0"/>
</system.web>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
</assemblyBinding>
</runtime>
</configuration>
Delete your bin folder, and packages.config file, if they exist. This is because we must assume that something in that bin folder is corrupt since IIS is designed to run Razor/ASP. In your visual studio project you will need to refresh your project so it knows these files have been deleted. This can be done by clicking the refresh button in the menu on the top of the Solution Explorer frame. In you visual studio project go to Tools > NuGet Package Manager > Package Manager Console and enter the following two commands.
Install-Package Microsoft.AspNet.Razor -Version 3.0.0
Install-Package Microsoft.AspNet.WebPages
This was enough to get *.cshtml pages to be rendered by IIS 10 on Windows 10 Pro.

ASP.NET - Deployment Issues - Enabling Stack Trace / Trace Listener Log via the Web.Config to find the cause of Internal Server 500 Error

I am getting a Internal Server 500 error after deploying an application that has compiled without errors on my local machine. The server that the application is deployed on has a ton of security so I need to specify read and write access for every directory. This application uses windows authentication and a web service to populate drop down boxes via a proxy. I think there might be an issue connecting to the web service or an issue with the read/write security on the files, or an issue with the active directory authentication.
I edited the web.config so that it would display more information as to the cause of the error with the following code:
<system.web>
<customErrors mode ="Off"></customErrors>
<compilation debug="true" strict="false" explicit="true" targetFramework="4.0" />
<trace enabled="true" pageOutput="true" />
<authentication mode="Windows"/>
<authorization>
<allow roles="alg\ADMIN_USER" />
<deny users="*" />
</authorization>
<client>
<endpoint address="http://63.236.108.91/aCompService.svc" binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_IAcompService" contract="aComp_ServiceReference.IAcompService"
name="BasicHttpBinding_IAcompService" />
</client>
I am now getting the following Error:
500 - Internal server error.
There is a problem with the resource you are looking for, and it cannot be
displayed.
I would like to see the stack trace with the source of the error.
What am I supposed to put in the web.config file so it displays the full stack trace?
What needs to be changed on the website from locally run to deployment?
Update- The deployment guy lifted some security read/write restrictions and now I get
Parser Error Message: The connection name 'ApplicationServices' was not found in
the applications configuration or the connection string is empty.
To get rid of the error, I removed the AspNetSqlRoleProvider declared on Line 72 and still
got an error. I then removed the AspNetWindowsTokenRoleProvider and all the provider info
and got the following Error:
Exception message: Default Role Provider could not be found.
Our hosting is done all remotely but the server guy can login to the local webserver remotely. It looks like the server guy didn't post the files in the right place. Now, I now get the error:
There is a problem with the resource you are looking for, and it cannot
be displayed.
Any ideas on how to fix these issues?
Thanks for looking!
Do you have a web.config at another location in the application's folder hierarchy that could be overriding the change you're making? I've seen confusion before when devs have copied a web.config up a level to retain a copy of it while making test changes.
That can be a source of much head-scratching.
Perhaps using impersonation should help?
I added the following in web.config:
<authentication mode="Windows"/>
<identity impersonate="true"/>
I added WriteToEventLog code so that I can track errors in the event log by the method.
Catch Ex As Exception
WriteToEventLog(Ex.Message, "GetCarriers-Method", EventLogEntryType.Error, "aComp-utility")
Catch ex As Exception
WriteToEventLog(ex.Message, "GetMarketingCompanies-Method", EventLogEntryType.Error, "aComp-utility")
Perhaps adding a TraceListenerLog should help?
Reference MSDN for more info on this code. I added the following in web.config:
<configuration>
<system.diagnostics>
<trace autoflush="false" indentsize="4">
<listeners>
<add name="myListener"
type="System.Diagnostics.EventLogTraceListener"
initializeData="TraceListenerLog" />
</listeners>
</trace>
</system.diagnostics>
</configuration>
should i also add the following on default.aspx.vb ?
Overloads Public Shared Sub Main(args() As String)
' Create a trace listener for the event log.
Dim myTraceListener As New EventLogTraceListener("myEventLogSource")
' Add the event log trace listener to the collection.
Trace.Listeners.Add(myTraceListener)
' Write output to the event log.
Trace.WriteLine(myTraceListener)
End Sub 'Main
I was able to over come this same problem by making a copy of my config file and then removing one segment and then testing the results one step at a time. What I discovered is that after I removed my handelers it worked fine.

Publish is not transforming web.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.

Resources