.NET MVC – Illegal characters in path

Scenario
Render a ASP.NET MVC Razor view with a model from the controller.

Error / Exception
System.ArgumentException: Illegal characters in path.

Cause
The model from the controller was returning JSON and the view had declared “@model string” to handle the JSON.

Solution
Updates in both controller and view. Change controller return type from string to the object.

Controller
Original: return View(JsonConvert.SerializeObject(List));
Change to: return View(List);

View
Original: @model string
Change to: @model List<object>

Error when reading from PFX certificate SSL/TLS

Case
Establish a secure connection to a server. Authentication with certificate.

Error message
The request was aborted: Could not create SSL/TLS secure channel.

  1. Start Microsoft Management Console, either from control panel or by run command “mmc”.
  2. In MMC select File > Add/Remove Snap-In (Ctrl+M).

    mmc add remove snap in
  3. Select Certificates > Add > OK. In next window select Local Computer.

    mmc add certificate
  4. When Certificates is added select Certificates > Personal > Certificates.
  5. You can see all the installed certificates in the window to the right. In order to add a permission right-click on a certificate and select All Tasks > Manage Private Keys.

    mmc manage private keys
  6. Search for user IIS_IUSRS (IIS User) and then add the user. You can configure the permissions like full control, read etc.
    when the user is added.

    mmc add iis user

Problems connecting to WCF service

Trying to connect to a WCF-service but get some error messages:

The HTTP request is unauthorized with client authentication scheme Anonymous The authentication header received from the server was Basic

The provided URI scheme https is invalid expected http

The solution was to adjust web.config > system.serviceModel section. Add “Transport” to security mode. and clientCredentialType should be “Basic” if the server expects Basic Realm.

  <system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="Document_Binding" closeTimeout="01:00:00" openTimeout="01:00:00" receiveTimeout="01:00:00" sendTimeout="01:00:00" maxReceivedMessageSize="2147483647">
          <security mode="Transport">
            <transport clientCredentialType="Basic" />
          </security>
        </binding>
      </basicHttpBinding>
    </bindings>
    <client>
    <endpoint ....../>
    </client>
  </system.serviceModel>

Good luck with your connections =)

Unable to connect to SQL DB via SSMS on Azure VM

I’ve installed SQL Server 2016 Express on a Azure Virtual Machine (VM). I opened the ports (port 1433) to connect to the server via Sql Server Management Studio (SSMS) but access was denied. I also opened the port inside the Azure portal on the server but still no success.
Then I came over a solution to the connection problem. You need to set the port number on IPAll among IP Addresses inside TCP/IP in Sql Server Configuration Manager. See screenshot below.

sql-server-ip-address
TCP Port 1433

How to navigate to the TCP Port setting:

  1. Open Sql Server Configuration Manager.
  2. Click on “Protocols” for “{INSTANCE NAME}” under Sql Server Network Configuration.
  3. Double click on TCP/IP.
  4. Click on tab “IP Addresses”.
  5. Scroll to the bottom and write the port number (1433 is default).

Good luck!

Copy files using a runtime created batch file C#

If you would like to copy one or several files using a batch file. The command for that is “copy {target} {destination}”. It’s also possible to use wildcards i.e “copy *.txt c:\temp”.
To create a bat (batch) file on runtime and then execute the file you could write something like this in C#.


string batchFileName = @"C:\{filePath}\copy.bat";
System.IO.File.WriteAllText(batFileName, @"copy {fileName}.{extension} {destination-filePath}");
System.Diagnostics.Process.Start(batFileName);

sqlI have a table in Microsoft SQL Server where insert or updates isn’t possible. Table is only responsible to increment a unique id.

The table looks like this:

CREATE TABLE [dbo].[CustomerOrderNumbers](
[customerOrderNumberId] [int] IDENTITY(1,1) NOT NULL,
[createdOn] [datetime] NOT NULL,
[isDeleted] [bit] NOT NULL,
PRIMARY KEY CLUSTERED
(
[customerOrderNumberId] ASC
)WITH (STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
GO

ALTER TABLE [dbo].[CustomerOrderNumbers] ADD DEFAULT (getdate()) FOR [createdOn]
GO

ALTER TABLE [dbo].[CustomerOrderNumbers] ADD DEFAULT ((0)) FOR [isDeleted]

But how do you increase the primary key when you can’t insert any values?

Answer, insert default value:
INSERT INTO [CustomerOrderNumbers] DEFAULT VALUES

This command also works with Azure SQL database.

Cordova build APK – Package damaged

I tried to build an APK (Android) in Cordova, build is successful so far so good!
When transferring the file to my mobile I got error message during install “Installation is not possible, package is damaged”. I created a new Cordova project and compared my “config.xml” file with the one in the project that failed. Found out that the “android-versionCode” is causing the problem. This is specified in the top of the config.xml. Remove that and the install is successful!

Use only Swedish servers in tor browser

If you want to use only Swedish servers in Tor browser (or any other country) to connect on you can do it like this:
1. Open the file “torrc” at “Tor Browser\Browser\TorBrowser\Data\Tor\”.

2. Add line “ExitNodes {countryCode}”.
You can use country code se for swedish, gb or us for english and so on) at end of the file.
3. Save the file and restart the browser.

 

Unable to launch the IIS Express Web server

Unable to launch the IIS Express Web server.
Output from IIS Express. Failed to register URL for site. The format of the specified network name is invalid 0x800704BE.

The error occured beacause I had a IP binding to 192.168.0.50 added with: “netsh http add iplisten 192.168.0.50”

To remove IP-binding you can use the following command (requires admin permission)

1. Remove current ip listening: netsh http delete iplisten {ip-address}
2. Listen to all ip addresses: netsh http add iplisten 0.0.0.0