How to verify that WebMatrix is performing web.config transformations? - visual-studio

I have an MVC5 project that I'm publishing to Azure via WebMatrix, where I've defined a connection string for the database server in production in the web.config like this:
<configuration>
<connectionStrings>
<add
name="MyProjectContainer"
providerName="System.Data.EntityClient"
connectionString="[metadata stuff];
provider=System.Data.SqlClient;
provider connection string="
data source=x1.database.windows.net,1433;
initial catalog=MyProject;
Uid=x#x1;
app=EntityFramework;
Pwd=xxx
""
/>
</connectionStrings>
...for local development I have an entry in the web.Debug.config like this:
<connectionStrings>
<add xdt:Transform="Replace" xdt:Locator="Match(name)"
name="MyProjectContainer"
providerName="System.Data.EntityClient"
connectionString="[metadata stuff];
provider=System.Data.SqlClient;
provider connection string="
data source=MyDevServer;
initial catalog=MyProject;
integrated security=True;
multipleactiveresultsets=True;
App=EntityFramework
""
/>
I chose this approach because having an empty connectionString in the web.config with a transform in web.Release.config didn't seem to work. when I publish my app works on Azure, however, when I try to run it locally, Visual Studio is trying to connect to the Azure database instead of the local server.
So I have 2 questions:
What could I be missing that transforms aren't working when I publish in WebMatrix? because if I could make that work I would have the connectionString in the main web.config as empty and the right values in web.Debug.config and web.Release.config
What is wrong with Visual Studio that it doesn't know how to do the transforms either?
has anyone out there struggled with this?

Related

.Net Core 2.1 Error 413 on multipart/form-data POST only on IIS not IIS Express

I'm hitting a problem with multipart/form-data POST uploads on IIS. My client is an Angular SPA and my backend is on .Net Core 2.1 (I know it's old).
The backend project is published as Self-Contained win-x64. I'm not sure how it's configured exactly on IIS / Kestrel but the IIS App runs under a specific Application Pool (No managed Code / Integrated). My web.config looks like this:
<configuration>
<location path="." inheritInChildApplications="false">
<system.web>
<httpRuntime maxRequestLength="1048576" />
</system.web>
<system.webServer>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="1073741824" />
</requestFiltering>
</security>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" />
</handlers>
<aspNetCore processPath=".\my.app.exe" stdoutLogEnabled="false" stdoutLogFile=".\log\path" />
</system.webServer>
</location>
</configuration>
In my development environment instead I'm using IIS Expres.
Now I added a multipart/form-data upload, sending form data together with a blob/image. This worked out of the box in development settings. However when I publish to staging environment with real IIS and the above web.config, I always get 413 Request entity too large.
My controller looks like this:
[HttpPost]
[DisableRequestSizeLimit]
[RequestFormLimits(MultipartBodyLengthLimit = int.MaxValue, ValueLengthLimit = int.MaxValue)]
[RequestSizeLimit(int.MaxValue)]
[Route("my/route")]
public ActionResult MyHandler()
I also added limits for Kestrel in Program.cs:
.UseKestrel(options =>
{
options.Limits.MaxRequestBodySize = 104857600; // 100MB
}
)
And to make the weirdness complete the 413 in staging environment only happens in Firefox. I have no idea what else I can do. I also cleared cache in firefox.
After longer search I finally found the necessary setting in IIS to make this work in Firefox. And it has indeed be mentioned in a few sources as the 'last option'. For me it was necessary in this case.
In 'IIS Manager' I selected the backend application and opened 'Configuration Editor'
system.webServer/serverRuntime -> uploadReadAheadSize=2147483647
That maked it work.

How to allow a DELETE method with IIS Express and Web API?

I am trying to send a delete request to my Web API service via Fiddler and am getting back a 405 "Method not allowed" error.
I have read extensively about removing the "WebDAV" module in web.config and similar suggestions (WebDAV is not enabled in my applicationhost.config anyway), but nothing I have tried has worked.
My service is currently running on IIS Express 10 (launching from Visual Studio). I do have this in my web.config file:
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler"
preCondition="integratedMode,runtimeVersionv4.0"/>
I would have thought the verb="*" piece would have allowed DELETE, but it does not seem to work.
One other note - when I inspect the response in Fiddler, under the Security heading it says: Allow: GET, POST.
I am not sure where that "Allow" parameter is being set (I am new to Web API).
Any help would be greatly appreciated. Please let me know what other information you need from me and I will add it.
Thank you!
Just reproduced this by creating a new webapi project [targeting .net framework 4.7.1]
Through Fiddler, I can hit the DELETE endpoint without any changes to web.config.
Please make sure to use correct endpoint including the id parameter.
e.g http:localhost:xxxx/api/values/id // please include the id and xxxx is port number.
If http:localhost:xxxx/api/values is used without id , I get the same result 405 Method Not Allowed
Hope this helps.
You can modify the IIS Express applicationHost.config in the %userprofile%\documents\IISExpress\config folder.  To enable PUT and DELETE for extensionless Urls scroll down to the bottom of the IIS Express applicationHost.config file and look for a handler entry that starts with: <add name="ExtensionlessUrl-Integrated-4.0".... In the "verb" attribute add PUT and DELETE so the "verb" attribute looks like:  verb="GET,HEAD,POST,DEBUG,PUT,DELETE"
Update your web config like this
<system.webServer>
<validation validateIntegratedModeConfiguration="false"/>
<modules runAllManagedModulesForAllRequests="true">
<remove name="WebDAVModule"/> <!-- ADD THIS -->
</modules>

Keyword not supported: 'metadata'

I am trying to publish my mvc 3 project but i can`t connect to the sql server(using EF), because of the wrong connection string. Here it is:
<add name="PackStoreEntities" connectionString="metadata=res://*/Models.PackStore.csdl|res://*/Models.PackStore.ssdl|res://*/Models.PackStore.msl;provider=System.Data.SqlClient;provider connection string="workstation id=PackStore.mssql.somee.com;packet size=4096;user id=*****;pwd=****;data source=PackStore.mssql.somee.com;persist security info=False;initial catalog=PackStore"" providerName="System.Data.EntityClient" />
I took this part form the my hoster:
workstation id=PackStore.mssql.somee.com;packet size=4096;user id=*****;pwd=****;data source=PackStore.mssql.somee.com;persist security info=False;initial catalog=PackStore
Mvc project works well on the local server, but when publishing i get "Keyword not supported: 'metadata' " . Where is my mistake? Thnaks for the answers.
try this one...
<add name="PackStoreEntities" connectionString="metadata=res://*;provider=System.Data.SqlClient;provider connection string='Data Source=PackStore.mssql.somee.com;Initial Catalog=PackStore;User ID=***;Password=****;'" providerName="System.Data.EntityClient" />
Edit..
<add name="PackStoreEntities" connectionString="metadata=res://*;provider=System.Data.SqlClient;provider connection string='workstation id=PackStore.mssql.somee.com;packet size=4096;user id=*****;pwd=****;data source=PackStore.mssql.somee.com;persist security info=False;initial catalog=PackStore;'" providerName="System.Data.EntityClient" />
I got this error while converting from Linq To Sql to Entity framework as well, even after fixing my connection strings. It turned out some asp:SqlDataSource controls needed to be switched to asp:EntityDataSource.
Before:
<asp:SqlDataSource ID="SqlDataSourceProducts" runat="server" SelectCommand="SELECT Id, Description FROM [Product]"
ConnectionString="<%$ ConnectionStrings:crmConnectionString %>" CacheDuration="5" CacheExpirationPolicy="Absolute">
</asp:SqlDataSource>
After:
<asp:EntityDataSource ID="SqlDataSourceProducts" runat="server" Select="Id, Description"
EntitySetName="Products" ConnectionString="<%$ ConnectionStrings:crmConnectionString %>" DefaultContainerName="CRM" >
</asp:EntityDataSource>
In your web.config you need to have two separate connections: One is for the Entity Frame work and one is for ADO.net
Should look like this:
<connectionStrings>
<add name="LoginDB" connectionString="Data Source=****;Initial Catalog=int422_113b16;User ID=****;Password=****" />
<add name="BlogEntities" connectionString="metadata=res://*/App_Code.BlogModel.csdl|res://*/App_Code.BlogModel.ssdl|res://*/App_Code.BlogModel.msl;provider=System.Data.SqlClient;provider connection string="data source****;initial catalog=int422_113b16;user id=****;password=****;multipleactiveresultsets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
</connectionStrings>
Remove he meta data from your connection string. That is only for the local debugging. For the online application can does not require that.
Kindly try the connection string given by naim
Had a similar problem, seems like the connection string from the somee server has to be between two "
That's all I changed and it works...
I'm not sure why people think that you need two connections in your web.config, that's not true. First thing I like to check is to see if my connection works in Visual Studio. Try going to your server explorer and connect to your database there. If you are able to connect with no problem and you are able to see your tables then you know its not a connection problem. Second thing make sure that your Model name matches the name in your web.config. This minimizes the amount of confusion in your project and finally make sure that your model name space points to your projects namespace, this way you can just call on your model by its name and not have to import or fully qualify it.
You should be able to create a strong view using any of the tables in your model. That's what I did for mine, I didn't modify the connection string like many suggest, or removed the metadata.
Check this troubleshooting guide it might shine some light, and help you understand how the entity connection works.
I had the same exception, but was able to fix it by keeping the ConnectionString the same but using an EntityConnection instead of a SqlConnection.

Html.Telerik().StyleSheetRegistrar() output file generating 404 message on asset.axd

I'm using the Telerik controls form MVC and they work great in my work/home dev environments, and in the work prod environment, but when I tried to deploy to my home prod environment (IIS7) I get a problem.
I've added the axd mime type, but wan't sure what else to do.
I read a post suggesting adding a handler, but wasn't sure if I'm setting that wrong or I'm just looking in the wrong direciton.
if you're on IIS7 make sure you add the handler to the <system.webServer><handlers> section:
<add name="MyName" path="MyName.axd" verb="*" type="NameSpace.Class, Assembly" />
I added: <add name="ScriptRegistrar" path="Access.axd" verb="*" type="Telerik.Web.Mvc.UI.ScriptRegistrar, Version=v2.0.50727" />
http://localhost:1000/asset.axd?id=sQAAAB-LCAAAAAAABADsvQdgHEmWJSYvbcp7f0r1StfgdKEIgGATJNiQQBDswYjN5pLsHWlHIymrKoHKZVZlXWYWQMztnbz33nvvvffee--997o7nU4n99__P1xmZAFs9s5K2smeIYCqyB8_fnwfPyJ-8UfT9qNHH7X5u_butGk-Gn10SX_u7ezujHfH93Ye0gfTjx619TqnX2YfPbr36f3RR_Tze7_4oxU1PKmWbb5s775ur8scb5_zV9VHj3ZGHy2pwbRaLKrlGKB_yYi_2JUv2rzM6-LtuN9gL2xwWTRtJt9__5d8_5f8PwEAAP__qtxwmrEAAAA%3d
To enable web resource combining with the Telerik Extensions you need to register the WebAssetHttpHandler in your webconfig:
IIS 7
<add name="AssetHandler" preCondition="integratedMode" verb="GET,HEAD" path="asset.axd" type="Telerik.Web.Mvc.WebAssetHttpHandler, Telerik.Web.Mvc"/>
IIS 6
<add verb="GET,HEAD" path="asset.axd" validate="false" type="Telerik.Web.Mvc.WebAssetHttpHandler, Telerik.Web.Mvc"/>
This handler enables you to use the Combine, Compress, and Cache features of the Script and StyleSheet Registrars. You can learn more and see additional config details in the Telerik online docs:
http://www.telerik.com/help/aspnet-mvc/web-assets-working-with-javascript-web-assets.html

'Username cannot be found' after modifying provider element

I am having trouble hitting the ASPNETDB.MDF database. It actually works fine until I add some code to the web config. This is the code I added that prevents me from connecting...
<membership defaultProvider="CustomizedProvider">
<providers>
<add name="CustomizedProvider"
type="System.Web.Security.SqlMembershipProvider"
connectionStringName="LocalSqlServer"
applicationName="MyApp"
minRequiredPasswordLength="5"
minRequiredNonalphanumericCharacters="0"
/>
</providers>
</membership>
I added it because I wanted to take advantage of the password constraints it affords. That said, the name of the connection string hasn't changed and no code change. But when I try to log in its telling me that the username cannot be found. I should ntoe that I am using the same un and pw which, by the way, meet these new constraints.
This is an ASP.NET 4.0 application
There doesn't seem to be anything wrong with the syntax, if the connection string name is correct then are you sure the application name is correct? This should be the application name in the database (defaults to '/') not the name of your application in visual studio.

Resources