Not sure why I am getting this error. It is a practice code so I learn the Entity Framework Code first approach.
I have the following in the web.config
<add name="CompanyDBContext"
connectionString="server=.; database=CompanyDB;integrated security=true;"
providerName="System.Data.SqlClient"/>
<connectionStrings>
and the following class
public class CompanyDBContext: DbContext
{
public DbSet<Department> Departments { get; set; }
public DbSet<Employee> Employees { get; set; }
}
The error is:
HTTP Error 500.19 - Internal Server Error
The requested page cannot be accessed because the related configuration data for the page is invalid.
Thanks in advance!
The Connection string format is wrong. The correct is:
<connectionStrings>
<add name="CompanyDBContext"
connectionString="server=.; database=CompanyDB;integrated security=true;"
providerName="System.Data.SqlClient"/>
</connectionStrings>
Related
I've tried resolving this from answers in other and similar posts, but no luck.
I'm Using MVC 5, framework 4.8 latest VS2017.
Thanks
My Config is: (including other attempts)
<configuration>
<appSettings>
<!--<add key="owin:AutomaticAppStartup" value="false" />-->
<add key="owin:HandleAllRequests" value="true"/>
<!--<add key="owin:AppStartup" value="Api.xxx" />-->
</appSettings>
</configuration>
Startup class is:
[assembly: OwinStartupAttribute(typeof(Api.xxx.Startup))]
namespace Api.xxx
{
public class Startup
{
public void Configuration(IAppBuilder app)
{
// Allow all origins
app.UseCors(Microsoft.Owin.Cors.CorsOptions.AllowAll);
….
}
}
}
and Api is:
namespace Api.xxx
{
[Route("values")]
public class ValuesController : ApiController
{
private static readonly Random _random = new Random();
public IEnumerable<string> Get()
{
var random = new Random();
return new[]
{
_random.Next(0, 10).ToString(),
_random.Next(0, 10).ToString()
};
}
}
}
I think you need to change
[assembly: OwinStartupAttribute(typeof(Api.xxx.Startup))]
to
[assembly: OwinStartup(typeof(Api.xxx.Startup))]
Reference: https://learn.microsoft.com/en-us/aspnet/aspnet/overview/owin-and-katana/owin-startup-class-detection
So i had this working, ive switched to paket and i guess some versions of dll's have changed.
However I still do not understand the error i am getting.
System.ArgumentException : LoggerName already in use
Parameter name: loggerName
my code is basically exactly as it is on here
http://www.tomdupont.net/2015/06/capture-xunit-test-output-with-nlog-and.html
public class NLogTests : IDisposable
{
private readonly ILogger _logger;
public NLogTests(ITestOutputHelper outputHelper)
{
_logger = outputHelper.GetNLogLogger();
}
public void Dispose()
{
_logger.RemoveTestOutputHelper();
}
[Fact]
public void Hello()
{
_logger.Trace("World Trace");
_logger.Debug("World Debug");
_logger.Warn("World Warn");
_logger.Error("World Error");
}
}
and config
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
throwExceptions="true">
<extensions>
<add assembly="xunit.NLog" />
</extensions>
<targets async="false">
<target xsi:type="TestOutput"
layout="${time}|${level:uppercase=true}|${logger}|${message}"
name="Test" />
</targets>
<rules>
<logger name="*" minlevel="Debug" writeTo="Test" />
</rules>
</nlog>
The GetNLogLogger method has an overload that takes a logger name and a bool for incremental suffixes. Using these does not help.
I am really confused.
stacktrace:
System.ArgumentException
LoggerName already in use
Parameter name: loggerName
at Xunit.NLog.Targets.TestOutputTarget.Add(ITestOutputHelper testOutputHelper, String loggerName)
at Xunit.NLog.Helpers.TestOutputHelpers.AddTestOutputHelper(ITestOutputHelper testOutputHelper, String loggerName, Boolean addNumericSuffix)
at Xunit.NLogTestOutputExtensions.GetNLogLogger(ITestOutputHelper testOutputHelper, String loggerName, Boolean addNumericSuffix)
at ProjectRake.BusinessLogic.Spec.TautologiesToVerifyNLogOutput..ctor(ITestOutputHelper outputHelper) in M:\programming\ProjectRake\src\server\ProjectRake.BusinessLogic.Spec\TautologiesToVerifyNLogOutput.cs:line 19
edit:
have downgraded all xunit stuff to 2.1.0, same issue.
outputHelper.GetNLogLogger(); is calling AddTestOutputHelper("")
I guess it only works if you call it once.
You can use outputHelper.GetNLogLogger("myname"); or outputHelper.GetNLogLogger(typeof(NLogTests).Name);
I encountered above exception after migrating an application from QuartzMDB with quartz-ra.rar to EJB Timers in Jboss AS 6.1 . (As a part of upgrading application to wildfly 8.1)
Exception is occurred at a job that uses following ejb.
#Stateless
#TransactionAttribute(TransactionAttributeType.REQUIRED)
#RolesAllowed({"admin"})
public class PlatformPluginBean implements PlatformPluginRemote {
// some code here
public Collection<PlatformPlugin> getPlugins() {
return new ArrayList<PlatformPlugin>(schemaToPlugin.values());
}
}
Following is the job before migration which worked fine.
#MessageDriven(activationConfig = {
#ActivationConfigProperty(propertyName = "cronTrigger", propertyValue = "0 0 * * * ?"),
#ActivationConfigProperty(propertyName = "jobName", propertyValue = "PruneJob")})
#ResourceAdapter("quartz-ra.rar")
#RunAs("admin")
public class PruneJob implements Job {
#EJB
private PlatformPluginRemote platformPluginRemote;
#Override
public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
for (PlatformPlugin platformPlugin: platformPluginRemote.getPlugins()) {
// some stuff here
}
}
}
Following is the job after changing to ejb auto timer.
#Stateless
#RunAs("admin")
public class PruneJob {
#EJB
private PlatformPluginRemote platformPluginRemote;
#Schedule(hour="*", minute="0", persistent=false)
public void execute() {
for (PlatformPlugin platformPlugin: platformPluginRemote.getPlugins()) {
// some stuff here
}
}
}
The exception is occurred at platformPluginRemote.getPlugins() call.
#RunAs("admin") annotation doesn't seem to work for some reason (jboss bug?)
Same can be done by adding following code before the call to ejb.
SecurityContextAssociation.getSecurityContext().setOutgoingRunAs(new RunAsIdentity("admin", "admin"));
There's this issue reported in JBoss 5 which also affects jboss as 6.1, to fix it you can add in file JBOSS_HOME/serve/<instance>/deploy/ejb3-interceptors-aop.xml the org.jboss.ejb3.security.RunAsSecurityInterceptorFactory interceptor:
eg:
<! - The additional MDB specific ones ->
<interceptor-ref name = "org.jboss.ejb3.ENCPropagationInterceptor" />
<interceptor-ref name = "org.jboss.ejb3.security.RunAsSecurityInterceptorFactory" />
<interceptor-ref name = "CMTTx" />
<interceptor-ref name = "org.jboss.ejb3.stateless.StatelessInstanceInterceptor" />
<interceptor-ref name = "org.jboss.ejb3.tx.BMTTxInterceptorFactory" />
<interceptor-ref name = "org.jboss.ejb3.AllowedOperationsInterceptor" />
<interceptor-ref name = "org.jboss.ejb3.entity.TransactionScopedEntityManagerInterceptor" />
In practice it has presented me some problems, not all invocations the role is propagated and some times authorization error occurs.
Alternatively you can use Subject.doAs() in execute() method of the MDB. Do not forget to add the login module ClientLoginModule in your security domain.
I've created a Sitefinity widget with only and iframe in it.
<%# Control Language="C#" AutoEventWireup="True" CodeBehind="ApplicationFrame.ascx.cs"
Inherits="MyProject.Web.Ui.Customized.EmbeddedApplications.ApplicationFrame" %>
<iframe runat="server" id="ApplicationIFrame" height="250" width="250" scrolling="no" frameborder="0" seamless="seamless" src=""></iframe>
In the Page_Load of the widget I trie to access any properties of the server side iframe but I always get "Object reference not set to an instance of an object".
Here's the C#
namespace MyProject.Web.Ui.Customized.EmbeddedApplications
{
[ControlDesigner(typeof(ApplicationFrameDesigner))]
public partial class ApplicationFrame : System.Web.UI.UserControl
{
public string FrameSourceUrl {get;set;}
public string FrameHeight { get; set; }
public string FrameWidth { get; set; }
protected void Page_Load(object sender, EventArgs e)
{
//set the values of the iframe to the current properties
ApplicationIFrame.Attributes["src"] = FrameSourceUrl;
ApplicationIFrame.Attributes["height"] = FrameHeight;
ApplicationIFrame.Attributes["width"] = FrameWidth;
}
}
}
I recently change the project from a Website to a Web Application, but that hasn't seemed to impact the project in any way.
Other than that I can't see why this exception keeps being thrown no matter what I do.
Anyone else know what the problem might be?
Thanks,
Jacques
This may not work depending on the type of widget you have created. It would probably work for normal User controls, but not custom controls.
If you are following the sitefinity documentation, you can inherit from SimpleView. Then you have access to helper methods for retrieving controls from the template. So instead of this:
ApplicationIFrame.Attributes["src"] = FrameSourceUrl;
You can do this:
this.GetControl<HtmlControl>("ApplicationIFrame", true).Attributes["src"] = FrameSourceUrl;
I am a newbie at WCF. I created a WCF restful service in VS2010 (WCF service appl). It was targeted for Framework 4.0. I hosted this service on local IIS with appl pool set for framework 4.0. When I call the appl methods from browser or fiddler, they work fine. Now, I created a client console based. When I call any method from client I get the following Communication Exception:
** remote server returned an unexpected response: (405) Method Not Allowed.**
Service Interface file:
namespace MyService
{
[ServiceContract]
public interface ITestService
{
[WebGet(UriTemplate = "GetDateTime")]
[OperationContract]
string GetDateTime();
[WebGet(UriTemplate = "GetName")]
[OperationContract]
string GetName();
}
}
Class that implements the above interface:
namespace MyService
{
public class TestService : ITestService
{
public string GetDateTime()
{
return DateTime.Now.ToString();
}
public string GetName()
{
return "MY name is KingKong";
}
}
}
Web.config file:
<system.serviceModel>
<services>
<service behaviorConfiguration="ServiceBehavior" name="MyService.TestService">
<endpoint address="" behaviorConfiguration="web" binding="webHttpBinding" bindingConfiguration="" contract="MyService.ITestService">
</endpoint>
</service>
</services>
<behaviors>
<endpointBehaviors>
<behavior name="web">
<webHttp />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="ServiceBehavior">
<!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="true" />
<!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
TestService.svc
<%# ServiceHost Language="C#" Debug="true" Service="MyService.TestService" CodeBehind="TestService.svc.cs" %>
Client app.config:
<system.serviceModel>
<behaviors>
<endpointBehaviors>
<behavior name="">
<webHttp />
</behavior>
</endpointBehaviors>
</behaviors>
<client>
<endpoint address="http://localhost/BestService/TestService.svc"
binding="webHttpBinding" bindingConfiguration="" contract="MyService.ITestService"
name="MyClientConfig" kind="" endpointConfiguration="" />
</client>
</system.serviceModel>
Client program calling proxy class
static void Main(string[] args)
{
TestServiceClient proxy = null;
try
{
proxy = new TestServiceClient();
Console.WriteLine("Test 1: List all products");
string sdatetime = proxy.GetName();
Console.WriteLine("Datetime: {0}", sdatetime);
Console.WriteLine();
// Disconnect from the service
proxy.Close();
}
catch (CommunicationException cex)
{
if (cex.InnerException != null)
{
Console.WriteLine("{0}", cex.InnerException.Message);
}
else
{
Console.WriteLine("General exception: {0}", cex.Message);
}
}
catch (Exception e)
{
if (e.InnerException != null)
{
Console.WriteLine("{0}", e.InnerException.Message);
}
else
{
Console.WriteLine("General exception: {0}", e.Message);
}
}
Console.WriteLine("Press ENTER to finish");
Console.ReadLine();
}
I added a service reference to the application and the Reference.cs file has following partial code:
namespace MyClient.MyService {
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
[System.ServiceModel.ServiceContractAttribute(ConfigurationName="MyService.ITestService")]
public interface ITestService {
[System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/ITestService/GetDateTime", ReplyAction="http://tempuri.org/ITestService/GetDateTimeResponse")]
string GetDateTime();
[System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/ITestService/GetName", ReplyAction="http://tempuri.org/ITestService/GetNameResponse")]
string GetName();
}
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
public interface ITestServiceChannel : MyClient.MyService.ITestService, System.ServiceModel.IClientChannel {
}
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
public partial class TestServiceClient : System.ServiceModel.ClientBase<MyClient.MyService.ITestService>, MyClient.MyService.ITestService {
public TestServiceClient() {
}
public TestServiceClient(string endpointConfigurationName) :
base(endpointConfigurationName) {
}
public TestServiceClient(string endpointConfigurationName, string remoteAddress) :
base(endpointConfigurationName, remoteAddress) {
}
public TestServiceClient(string endpointConfigurationName, System.ServiceModel.EndpointAddress remoteAddress) :
base(endpointConfigurationName, remoteAddress) {
}
public TestServiceClient(System.ServiceModel.Channels.Binding binding, System.ServiceModel.EndpointAddress remoteAddress) :
base(binding, remoteAddress) {
}
public string GetDateTime() {
return base.Channel.GetDateTime();
}
public string GetName() {
return base.Channel.GetName();
}
}
}
Please help me as I have spent nearly 2 days trying to figure out the problem in the client
Thanks
VS2010 doesnt have the ability to generate a proxy for a RESTFUL service as it does for a SOAP based service. So the solution is write your own proxy class which inherits from the ClientBase class and use the Channel to call the web methods of the service.