I have a question regarding using LightSpeed in a MVC3 Web application. I am creating a REST Api project where I want to use LightSpeed, but the official configuration guidelines are quite vague. The official documentation says that the following lines need to be added to the file web.config:
<configSections>
<section name="lightSpeedContexts"
type="Mindscape.LightSpeed.Configuration.LightSpeedConfigurationSection, Mindscape.LightSpeed" />
</configSections>
<lightSpeedContexts>
<add name="Test" />
</lightSpeedContexts>
<lightSpeedContexts>
<add name="Test" dataProvider="SQLite3" />
</lightSpeedContexts>
I tried adding following lines to the web.config in the root:
<configSections>
<section name="lightSpeedContexts"
type="Mindscape.LightSpeed.Configuration.LightSpeedConfigurationSection, Mindscape.LightSpeed" />
</configSections>
<lightSpeedContexts>
<add name="Default" connectionStringName="Prod" dataProvider="MySQL5" />
</lightSpeedContexts>
<connectionStrings>
<add name="Prod" connectionString="server=localhost;User Id=production;password=xxx;Persist Security Info=True;database=CBS"/>
</connectionStrings>
This throws an exception when I start the Web application which tells me that configSections may not be specified more than once in the application. The root web.config file did not have any of these specified per default.
I am not sure where to put this configuration.
OK, I found out how to solve the problem.
I moved out the configSections that were in the two sub web.config files (in each Views folder) and put the contents in the main web.config file, then I added the lightSpeedContexts and connectionStrings in the main web.config file.
Related
There's LOADS of information on how to add MIME types into a normal project.
These include configuring IIS, or modifying the web.config.
Both of these options are unavailable to me in vNext with IIS Express.
I had a look at the schema to the project.json file and couldn't find anything in there that would help either.
Can this be done yet? - I want to add a mime type for the .woff2 extension.
If you hosting it on IIS 7 or later then following step will do what you need. This answer I have used Visual Studio 2015 CTP5.
Publish your web application ( ASP.net vnext)
You can publish it to location like C:\MyPublish
Once it get successfully published you will find following location C:\MyPublish\wwwroot. Here You will find web.config.
Now host your site to in IIS ( Make sure that you have used C:\MyPublish\wwwroot as your path)
Now edit web.config over here just like you did for old version to add mime type. ( Following is my edit)
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<appSettings>
<add key="kpm-package-path" value="..\approot\packages" />
<add key="bootstrapper-version" value="1.0.0-beta2" />
<add key="kre-package-path" value="..\approot\packages" />
<add key="kre-version" value="1.0.0-beta2" />
<add key="kre-clr" value="CLR" />
<add key="kre-app-base" value="..\approot\src\WebApplication5" />
</appSettings>
<system.webServer>
<staticContent>
<remove fileExtension=".woff" />
<mimeMap fileExtension=".woff" mimeType="application/font-woff" />
</staticContent>
</system.webServer>
</configuration>
Note: As per my thinking In old version it is fix that it is always windows environment so we have direct web.config file in project and we edit that but now we have to follow different process to register as in future we can host completly on linux env as well.
Update : There is another way to do that as well. If you are using Microsoft.AspNet.StaticFiles package then you will have extension.
public void Configure(IApplicationBuilder app)
{
app.UseStaticFiles();
}
This will indirectly use https://github.com/aspnet/StaticFiles/blob/dev/src/Microsoft.AspNet.StaticFiles/FileExtensionContentTypeProvider.cs. Here you can see all mapping.
Update 2: (Add New Mime Type)
public void Configure(IApplicationBuilder app)
{
StaticFileOptions option = new StaticFileOptions();
FileExtensionContentTypeProvider contentTypeProvider = (FileExtensionContentTypeProvider)option.ContentTypeProvider;
contentTypeProvider.Mappings.Add("<<yourextention>>","<<mimetype>>");
app.UseStaticFiles(option);
}
Until this is released, you can also edit applicationhost.config which I found in D:\Documents\IISExpress\config (yours might be on your C drive [Documents]).
I added:
<mimeMap fileExtension=".woff2" mimeType="font/x-woff2" />
Inside <staticContent>.
I've implemented authentication in my web application, Now problem is like at the time of deployment i've to do some manual settings in web.config file
like; every time if i want to deploy on test then i've to uncomment local testing settings and comment to production setting and vice versa, so is there any way that i can change these settings runtime or dynamically at the time of deployment? because i've lots of environment to publish so every time do manually comment and uncomment of setting is not worthy
<!--LOCAL TESTING-->
<add key="idaFederationMetadataLocation" value="https://login.windows.net/test.onmicrosoft.com/testMetadata/2007-06/testMetadata.xml" />
<add key="idaRealm" value="https://test.onmicrosoft.com/AadTest" />
<add key="idaAudienceUri" value="https://test.onmicrosoft.com/admTest" />
<add key="idaClientID" value="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" />
<add key="idaPassword" value="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx=" />
<!-- PRODUCTION -->
<!-- <add key="idaFederationMetadataLocation" value="https://login.windows.net/test.onmicrosoft.com/testMetadata/2007-06/testMetadata.xml" />
<add key="idaRealm" value="https://test.onmicrosoft.com/AadTest" />
<add key="idaAudienceUri" value="https://test.onmicrosoft.com/admTest" />
<add key="idaClientID" value="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" />
<add key="idaPassword" value="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx=" />-->
So you just need to comment one line in release version of your web.config?
You can use Web.Config Transformation. Add the following line to you Web.Release.config file:
<add key="idaFederationMetadataLocation" xdt:Transform="Remove" xdt:Locator="Match(key)"/>
My application is in Asp.Net MVC3, my application was running perfectly but all of a sudden i'm getting an error in my Web.Config in my role manager tag.
Below is my RoleManager tag of web.config
<roleManager defaultProvider="MASSIARoleProvider" enabled="true" cacheRolesInCookie="true">
<providers>
<clear />
<add name="MASSIARoleProvider" type="MASSIA.Helpers.MASSIARoleProvider, MASSIA" connectionStringName="MASSIAEntities" />
</providers>
</roleManager>
Below is the error i'm getting directly when i run my application:
[updated Error Image]
I have a file MASSIARoleProvider.cs in my solution in the directory Helper.
Below is Heirarchy of my RoleProvider file.
--> Massia --> Helpers --> MASSIARoleProvider.cs
My solution was executing perfectly but i'm getting this error all of a sudden.
<roleManager defaultProvider="MASSIARoleProvider" enabled="true" cacheRolesInCookie="true">
<providers>
<clear />
<add name="MASSIARoleProvider" type="MASSIA.Helpers.MASSIARoleProvider" connectionStringName="MASSIAEntities" />
</providers>
</roleManager>
Attemp 2:
Check for your MASSIARoleProvider file and see whether the Solution name and references used are perfectly correct.
Attempt 3:
The last and least recommended.
Create a new solution, if and only if your solution is in the beginning stage and try to reconfigure the RoleProvider. Once it solved the issue for me, I made a new solution, added the existing files to the news solution and executed the new solution and it executed perfectly. I did not made any change to the code, i just included the existing files from the old solution to the new one.
I am currently using Visual Studio 2010. I want to set up a different connection string for my "Testing" Configuration. I have tried doing it by using config transformations, but it does not seem to work.
In my Web.config my connection string is the following:
<add name="MyDb" connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=DevelopmentDb;Integrated Security=SSPI; MultipleActiveResultSets=True" providerName="System.Data.SqlClient" />
I found out that you can replace the connection string defined in Web.config by adding config transformation. I right clicked on Web.config and clicked on "Add config transformations". This created a Web.TEST.config file. I then added a connection string replacement, but it doesnt seem to work. It still uses the connection string defined in Web.config.
The file contents of Web.TEST.config is:
<?xml version="1.0"?>
<!-- For more information on using web.config transformation visit http://go.microsoft.com/fwlink/?LinkId=125889 -->
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<!--
In the example below, the "SetAttributes" transform will change the value of
"connectionString" to use "ReleaseSQLServer" only when the "Match" locator
finds an atrribute "name" that has a value of "MyDB".
-->
<connectionStrings>
<add name="MyDb"
connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=TestDb;Integrated Security=SSPI; MultipleActiveResultSets=True"
xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
</connectionStrings>
<system.web>
<!--
In the example below, the "Replace" transform will replace the entire
<customErrors> section of your web.config file.
Note that because there is only one customErrors section under the
<system.web> node, there is no need to use the "xdt:Locator" attribute.
<customErrors defaultRedirect="GenericError.htm"
mode="RemoteOnly" xdt:Transform="Replace">
<error statusCode="500" redirect="InternalError.htm"/>
</customErrors>
-->
</system.web>
</configuration>
Any ideas to what I could be missing?
Transformations get applied when you deploy the project, not when you compile it.
If you are using IIS, you can deploy to the configured web application directory, which will cause the transform to apply.
In ASP.NET MVC3 I notice that Application_BeginRequest gets called for my CSS and JS files as well. My CSS and JS files reside in the /Content and /Scripts folders respectively.
Is this correct? Is there really a need for these files to pass through the managed code pipeline?
The site runs on IIS7 (and the ASP.NET web server).
My modules configuration section looks as follows:
<modules runAllManagedModulesForAllRequests="false">
<remove name="UrlRoutingModule-4.0" />
<add name="UrlRoutingModule-4.0" type="System.Web.Routing.UrlRoutingModule" preCondition="" />
<add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah" preCondition="managedHandler" />
<add name="ErrorMail" type="Elmah.ErrorMailModule, Elmah" preCondition="managedHandler" />
<add name="ErrorFilter" type="Elmah.ErrorFilterModule, Elmah" preCondition="managedHandler" />
</modules>
You should check this answer. Most probably you have same issue. If not then I would check your pipeline mode + handlers configuration.
UPDATE: sorry, just saw that you already have [runAllManagedModulesForAllRequests="false"]. Do you use some profilers or custom virtual path providers?
In my case I use custom virtual path provider to serve files that are embedded into an assembly. For this purpose special configuration is created for a few subdirectories.
Own answer: In the end I could not figure out a way to not let static files go through the MVC pipeline. So I went for a hacky solution where I check the URL extension in Application_PostAuthenticateRequest and just return when static content is being requested (i.e. ".css", ".js" etc.)
Not pretty.