CheapWindowsHosting.com | Best and Cheap windows Hosting. By default IIS and ASP.NET aren’t configured as part of a Windows setup (for obvious reasons) so developers are used to having to register IIS manually before being able to run and develop ASP.NET web sites on their desktops.
This no longer works and requires a different command. Depending on what you already have enabled this may work
dism /online /enable-feature /featurename:IIS-ASPNET45
If you haven’t enabled anything related to IIS yet you can do that at the same time with:
dism /online /enable-feature /all /featurename:IIS-ASPNET45
However! That might not appear to solve the problem even when it has! A post from Microsoft makes a bug apparent:
After the installation of the Microsoft .NET Framework 4.6, users may experience the following dialog box displayed in Microsoft Visual Studio when either creating new Web Site or Windows Azure project or when opening existing projects.
Configuring Web http://localhost:64886/ for ASP.NET 4.5 failed. You must manually configure this site for ASP.NET 4.5 in order for the site to run correctly. ASP.NET 4.0 has not been registered on the Web server. You need to manually configure your Web server for ASP.NET 4.0 in order for your site to run correctly.
NOTE: Microsoft .NET Framework 4.6 may also be referred to as Microsoft .NET Framework 4.5.3
This issue may impact the following Microsoft Visual Studio versions: Visual Studio 2013, Visual Studio 2012, Visual Studio 2010 SP1
Select “OK” when the dialog is presented. This dialog box is benign and there will be no impact to the project once the dialog box is cleared. This dialog will continue to be displayed when Web Site Project or Windows Azure Projects are created or opened until the fix has been installed on the machine.
Microsoft has published a fix for all impacted versions of Microsoft Visual Studio.
Visual Studio 2013 –
Visual Studio 2012
Visual Studio 2010 SP1
CheapWindowsHosting.com | Best and cheap ASP.NET Core hosting. In this post we will show you how to running ASP.NET Core with IIS on Nano server.
First you need to install IIS on Nano.
Currently, both HttpPlatformHandler and Asp.Net Core Kestrel host requires Reverse Forwarders package to be installed on the Nano machine. Reverse Fowarders can be installed offline (machine turned off) or online (machine running).
Offline, Reverse Forwarders can be installed by passing –ReverseForwarders parameters when calling New-NanoServerImage cmdlet.
e.g. New-NanoServerImage -MediaPath f:\ -BasePath .\Base -TargetPath .\Nano1.vhd -GuestDrivers -Packages Microsoft-NanoServer-IIS-Package -ReverseForwarders
Online, Reverse Forwarders can be installed by calling dism on the relevant package:
In this case, C:\packages is a local directory that I created where I copied the Packages folder from the Nano Server media installation location.
After installing Reverse Forwarders package (whether offline or online), verify that IIS and Reverse Forwarders are correctly installed by running ‘dism /online /get-packages’.
You should see the Feature and Language packs for Microsoft-NanoServer-IIS-Package and Microsoft-OneCore-ReverseForwarders-Package.
At this time, the install for HttpPlatformHandler on Nano is manual.
Nano is 64 bit only (no WOW), so you’ll need to install the latest x64 version of HttpPlatformHandler (http://www.iis.net/downloads/microsoft/httpplatformhandler) on a regular (not Nano) machine.
Once you have x64 bit version of HttpPlatformHandler installed on your regular (not Nano) machine, there are 2 files which we’ll need to copy to the Nano machine:
On the Nano machine you’ll need to copy those 2 files to the respective locations (dll->inetsrv, schema file->inetsrv\config\schema)
You can execute the steps below in a remote PowerShell session to the Nano machine.
Note that the below steps works on a clean system, but is not meant to be idempotent. If you run this multiple times it will add multiple entries and you will run into problems!
If you end up in a bad state, you can find backups of the applicationHost.config file at %systemdrive%\inetpub\history.
Import-Module IISAdministration
$sm = Get-IISServerManager
# Add AppSettings section (for Asp.Net Core)
$sm.GetApplicationHostConfiguration().RootSectionGroup.Sections.Add("appSettings")
# Unlock handlers section
$appHostconfig = $sm.GetApplicationHostConfiguration()
$section = $appHostconfig.GetSection("system.webServer/handlers")
$section.OverrideMode="Allow"
# Add httpPlatform section to system.webServer
$sectionHttpPlatform = $appHostConfig.RootSectionGroup.SectionGroups["system.webServer"].Sections.Add("httpPlatform")
$sectionHttpPlatform.OverrideModeDefault = "Allow"
# Add to globalModules
$globalModules = Get-IISConfigSection "system.webServer/globalModules" | Get-IISConfigCollection
New-IISConfigCollectionElement $globalModules -ConfigAttribute @{"name"="httpPlatformHandler";"image"="%SystemRoot%\system32\inetsrv\httpPlatformHandler.dll"}
# Add to modules
$modules = Get-IISConfigSection "system.webServer/modules" | Get-IISConfigCollection
New-IISConfigCollectionElement $modules -ConfigAttribute @{"name"="httpPlatformHandler"}
$sm.CommitChanges()
You can skip this section if you already did the PowerShell steps above.
I recommend following the PowerShell steps, although if you absolutely must edit the IIS applicationHost.config file to enable HttpPlatformHandler then these are the steps.
Open up c:\windows\system32\inetsrv\applicationHost.config
(if you are using Powershell ISE v5 you can do this using ‘psedit c:\windows\system32\inetsrv\applicationHost.config’)
Under <configSections> add
<configSections>
<section name="appSettings" />
In system.webServer section, unlock handlers from Deny to Allow
<section name="handlers" overrideModeDefault="Allow" />
In system.webServer section, add new httpPlatform section
<section name="httpPlatform" overrideModeDefault="Allow" />
</sectionGroup>
Add the following to globalModules
<add name="httpPlatformHandler" image="%SystemRoot%\system32\inetsrv\httpPlatformHandler.dll" />
</globalModules>
Add the following to Modules
<add name="httpPlatformHandler" />
</modules>
First, make sure that your Asp.Net Core application is built targeting coreclr and x64.
This is very important as any other combination will not work on Nano.
After building for coreclr/x64 you will need to copy the whole application to the Nano machine – in this example I’m using c:\HelloAspNetCore.
Next I will setup a new Site pointing to c:\HelloAspNetCore\wwwroot using port 8000 (for simplicity we will go with Default App Pool)
There are no problems running the Asp.Net Core site on default port 80, though in a testing environment I like to separate the Asp.Net Core app from the default website, so that it’s easier to troubleshoot when something goes wrong (e.g. so you can verify that the default IIS site still works fine).
Using IIS PowerShell:
Import-module IISAdministration
New-IISSite -Name "AspNetCoreSite" -PhysicalPath c:\HelloAspNetcore\wwwroot -BindingInformation "*:8000:"
Creating the site manually (omit if you already created using PowerShell above) by editing c:\windows\system32\inetsrv\applicationHost.config:
<sites>
<site name="Default Web Site" id="1">
<application path="/">
<virtualDirectory path="/" physicalPath="%SystemDrive%\inetpub\wwwroot" />
</application>
<bindings>
<binding protocol="http" bindingInformation="*:80:" />
</bindings>
</site>
<site name="AspNetCoreSite" id="2">
<application path="/">
<virtualDirectory path="/" physicalPath="C:\HelloAspNetCore\wwwroot" />
</application>
<bindings>
<binding protocol="http" bindingInformation="*:8000:" />
</bindings>
</site>
… rest of xml…
</sites>
The next step is to open up port 8000 in the firewall.
New-NetFirewallRule -Name "AspNetCore" -DisplayName "HTTP on TCP/8000" -Protocol tcp -LocalPort 8000 -Action Allow -Enabled True
I have followed the steps, but it doesn't work 🙁
It gets a PERMISSION DENIED; I found it in the app /logs directory (included below).
Does it need an additional ICACL somewhere? I don't know under what security context it runs...
I think I saw somewhere it could need permission for the port it runs on. If so, how do we grant permissions on that port?
Microsoft.AspNet.Server.Kestrel.Networking.UvException: Error -4092 EACCES permission denied
at Microsoft.AspNet.Server.Kestrel.Networking.Libuv.Check(Int32 statusCode)
at Microsoft.AspNet.Server.Kestrel.Networking.UvTcpHandle.Bind(ServerAddress address)
at Microsoft.AspNet.Server.Kestrel.Http.TcpListener.CreateListenSocket()
at Microsoft.AspNet.Server.Kestrel.Http.Listener.<>c__DisplayClass5_0.<StartAsync>b__0(Object _)
CheapWindowsHosting.com | Run external app directly from RAM. You can load the specific file into a Byte [] Array with a StreamReader () or even download it from WEB via a direct link provided.
The point of this technique is to maintain anonymity to a fragile file, thus leaving no chance to a reverse engineer to crack the details.
Also note, to keep the variables such as the one referencing the MethodInfo()
on a Class
basis. You then should Dispose()
or set to Nothing
these variables at the FormClosing()
Event to prevent memory leak.
Dim method As System.Reflection.MethodInfo
Sub Run
Dim bb() As Byte = IO.File.ReadAllBytes("file.exe")
Try
Dim a As System.Reflection.Assembly = System.Reflection.Assembly.Load(bb)
'or a = Reflection.Assembly.Load(New WebClient().DownloadData("https://...."))
method = a.EntryPoint
If (Not method Is Nothing) Then
Dim o As Object = a.CreateInstance(method.Name)
method.Invoke(o, Nothing)
'if your app receives parameters
'method.Invoke(o, New Object() {New String(){"Hello}})
Else
Throw New NullReferenceException("method is null.")
End If
Catch ex As Exception
MsgBox(ex.Message & vbCrLf & "File length: = " & bb.Length.ToString)
End Try
End Sub
If your app is WinForms and not ConsoleApplication, then follow the steps below:
Your external application needs to start from a Main() Sub
to be compatible with this. Otherwise, change the solution property of your external app:
ApplicationFramework
Module1
)Module1
Module1
Public Sub Main()
Application.Run(New Form1)
'Form1 is your first WinForm that your app displays
End Sub
or if your app receives parameters:
Public Sub Main(ByVal args As String())
Application.Run(New Form1)
'Form1 is your first WinForm that your app displays
End Sub
I hope this post helpful for you 🙂
CheapWindowsHosting.com | Cheap and reliable ASP.NET State server. ASPHostPortal.com is Microsoft No #1 Recommended Windows and ASP.NET Spotlight Hosting Partner in United States. Microsoft presents this award to ASPHostPortal.com for the ability to support ASP.NET State server Service for session.
Many articles are discussing about advantages of using Session StateServer or SQLServer over InProc Mode. One basic reason why I choose StateServer Mode is when your website is running on Third Party Hosting than you will notice that Session Timeout can occur anytime depends on load of traffic on your server.
If your website has large number of visitors and session timeout can cause problem, It is better to change Session Mode Session=”InProc” to Session=”StateServer”.
Main Advantage of Session StateServer (Best to choose while hosting on third party server)
Main Disadvantage
Now lets understand
Steps for changing Session InProc Mode to Session StateServer Mode.
If you forget to Start Service you will receive following error.
Server Error in '/' Application.
Unable to make the session state request to the session state server. Please ensure that the ASP.NET State service is started and that the client and server ports are the same. If the server is on a remote machine, please ensure that it accepts remote requests by checking the value of HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\aspnet_state\Parameters\AllowRemoteConnection. If the server is on the local machine, and if the before mentioned registry value does not exist or is set to 0, then the state server connection string must use either 'localhost' or '127.0.0.1' as the server name.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Web.HttpException: Unable to make the session state request to the session state server. Please ensure that the ASP.NET State service is started and that the client and server ports are the same. If the server is on a remote machine, please ensure that it accepts remote requests by checking the value of HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\aspnet_state\Parameters\AllowRemoteConnection. If the server is on the local machine, and if the before mentioned registry value does not exist or is set to 0, then the state server connection string must use either ‘localhost’ or ‘127.0.0.1’ as the server name.
sessionState mode="StateServer"
stateConnectionString="tcpip=127.0.0.1:42424"
cookieless="false"
timeout="120"/>
Note: You can adjust timeout minutes based on your requirement. Let the tcpip server to be localhost i.e. 127.0.0.1. Most webhosting company uses these settings unless you have different IP for StateServer and You are not required to change Port Number.
You should make all object in your website to serializable.
Note: To take advantage of Session StateServer or SQLServer or Custom Mode, object needs to be serialized.
Example: If your project contains class files for creating DAL (Data Access Layer), you should append Serializable to every class definition in order to make class Serializable.
Class Department
{
long _deptId;
string _deptName;
public long DeptId
{
get { return _deptId; }
set { _deptId = value; }
}
public string DeptName
{
get { return _deptName; }
set { _deptName = value; }
}
}
IMPORTANT While doing Serialization
Remember SQLConnection cannot be serialized.
You might receive following error if you don’t handle this situation.
Unable to serialize the session state. In 'StateServer' and 'SQLServer' mode, ASP.NET will serialize the session state objects, and as a result non-serializable objects or MarshalByRef objects are not permitted. The same restriction applies if similar serialization is done by the custom session state store in 'Custom' mode.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Web.HttpException: Unable to serialize the session state. In ‘StateServer’ and ‘SQLServer’ mode, ASP.NET will serialize the session state objects, and as a result non-serializable objects or MarshalByRef objects are not permitted. The same restriction applies if similar serialization is done by the custom session state store in ‘Custom’ mode.
So to handle this situation you need to do following thing
Class Department: IDeserializationCallback
{
long _deptId;
string _deptName;
public long DeptId
{
get { return _deptId; }
set { _deptId = value; }
}
public string DeptName
{
get { return _deptName; }
set { _deptName = value; }
}
//Create this Method Inside your Class
void IDeserializationCallback.OnDeserialization(object sender)
{
//Recreate your connection here
_mainConnection = new SqlConnection();
_mainConnection.ConnectionString =
ConfigurationSettings.AppSettings["connStr"].ToString();
}
}
I hope this article helpful for you. Happy coding 🙂