How to setup Multiple sites (Multi domain sites) in one Sitecore instance in My Local Machine? - iis

I have been trying to configure multiple sites with multiple domain in my local instance.
Sitecore Content tree
Sitecore
-> Content
-> Home
-> PublicHome
I have the following web.config settings.
<site name="website" virtualFolder="/" physicalFolder="/" rootPath="/sitecore/content" startItem="/home" database="web" domain="extranet" allowDebug="true" cacheHtml="true" htmlCacheSize="10MB" registryCacheSize="0" viewStateCacheSize="0" xslCacheSize="5MB" filteredItemsCacheSize="2MB" enablePreview="true" enableWebEdit="true" enableDebugger="true" disableClientData="false"/>
<site name="PublicHome" hostName="my.public.com" virtualFolder="/" physicalFolder="/" rootPath="/sitecore/content" startItem="/PublicHome" language="en" database="web" domain="extranet" />
I have created couple of Host file entry.
127.0.0.1 My.Sitecore.com
127.0.0.1 my.public.com
My.Sitecore.com - Loading the Home Page.
But my.public.com is not loading as expected.
When binding was not setup in the IIS site. I was getting IIS Default site.
Once I add the binding on the IIS site. I was getting "Home" instead of "PublicHome".
Version info: Sitecore 7.5, IIS in Windows 10

To fix your immediate issue, add your custom site definition before the default "website" entry.
To better prepare yourself for future upgrades, utilize Sitecore patch attributes and a separate configuration file to apply your custom site definition. (i.e. <site name="PublicHome" patch:before="site[#name='website']">). Read about web.config patching to learn more.

Related

Monitoring triggers in web.config not working for .net core web app

I'm trying to implement a setting (see below) in a web.config file in a .NET Core web app. Web app is hosted in Azure.
The setting is placed in system.webServer section and should restart the worker process on slow responses according to article:
https://azure.microsoft.com/sv-se/blog/auto-healing-windows-azure-web-sites/
<monitoring>
<triggers>
<slowRequests timeTaken="00:01:00" count="10" timeInterVal="00:02:00" />
</triggers>
</monitoring>
But when publishing the config file with this setting the web app crashes with error messages:
HTTP Error 500.19 - Internal Server Error
The worker process is unable to read the applicationhost.config or web.config file.
The requested page cannot be accessed because the related configuration data for the page is invalid.
Anyone successfully implemented this setting in a .net core app hosted in Azure?
I found that one setting was missing. The complete monitoring tag should be:
<monitoring>
<triggers>
<slowRequests timeTaken="00:01:00" count="10" timeInterval="00:02:00" />
</triggers>
<actions value="Recycle" />
</monitoring>

Can Web Deploy create IIS Site and Application Pool

I am working on automation of deployment process and I need to find a way to build and deploy an asp.net web site.
On top of this I would also like to create IIS Site and Application Pool for newly created IIS if one doesn't already exist.
Is this possible with Web Deploy (or is there an even better way/tool/approach to achieve these goals?)
Consider using ServerManager class from Miceosoft.Web.Administration namespace. Specifically, ApplicationPools and Sites properties.
For example,
ServerManager sm = new ServerManager();
Site site = serverMgr.Sites.Add(“MySiteName”, “C:\\inetpub\\wwwroot”, 8080);
sm.ApplicationPools.Add(“MyAppPool”);
sm.CommitChanges()
For more information see https://msdn.microsoft.com/en-us/library/microsoft.web.administration.servermanager(v=vs.90).aspx
Hope this helps.
There's also MSBuildExtensionPack:
https://github.com/mikefourie/MSBuildExtensionPack
I imagine that said msbuild-family-of-actions employs the Microsoft.Web.Administration namespace to work its magic in terms of creating a new website in IIS 7 and the scripting looks something like this (haven't tested this on my own server yet):
<Target Name="ProvisionIIS7WebSite" DependsOnTargets="CreateDeploymentNumber">
<PropertyGroup>
<WebSiteName>$(BaseDeploymentName)$(DeploymentNumber)</WebSiteName>
<PortNumber>$(DeploymentNumber)</PortNumber>
</PropertyGroup>
<ItemGroup>
<WebApplication Include="/MyApp">
<PhysicalPath>$(WebSitePath)</PhysicalPath>
</WebApplication>
<VirtualDirectory Include="/MyVdir">
<ApplicationPath>/MyApp</ApplicationPath>
<PhysicalPath>$(WebSitePath)</PhysicalPath>
</VirtualDirectory>
</ItemGroup>
<!-- Create new site -->
<MSBuild.ExtensionPack.Web.Iis7Website TaskAction="Create"
Name="$(WebSiteName)"
Port="$(PortNumber)"
Path="$(WebSitePath)"
AppPool="$(WebSiteAppPool)"
Applications="#(WebApplication)"
VirtualDirectories="#(VirtualDirectory)">
<Output TaskParameter="SiteID" PropertyName="WebSiteID" />
</MSBuild.ExtensionPack.Web.Iis7Website>
<Message Text="Created website with ID $(WebSiteID)" />
</Target>

Remove Server Response Header IIS 8.0 / 8.5

How can we remove the server header response in IIS 8.0/8.5?
My current server report:
Microsoft-IIS/8.0
Microsoft-IIS/8.5
For IIS 7.0 I used the URLScan 3.1 however this is only supported for IIS 7.0 and not 8.x
There is another solution and in my opinion this solution is the best and safe.
You can use UrlRewrite module created by the Microsoft. The Url Rewrite module redirects your url and can also change your IIS server name in the response header.
You don't have to use redirect property. You can use just change the Server header value.
Here are the steps:
First, download UrlRewrite module from this link:
http://www.iis.net/downloads/microsoft/url-rewrite and install
it on your IIS server. After that, restart IIS by this command on cmd
console
iisreset /restart
Add the following item to the your web config file under the <system.WebServer> tag. You can write anything to the Value item as server name.
Finally we changed the IIS version name on the data's header. Restart IIS again. via cmd console.
Bonus: If you want to test your website to see if it is working or not... You can use "HttpRequester" mozilla firefox plugin. for this plugin: https://addons.mozilla.org/En-us/firefox/addon/httprequester/
PS: I tested it and it worked for me on the IIS server. Not on the has been created temproray IIS server by the Visual studio.
It is possible now to remove Server header from web.config starting from IIS 10.0 :
<security>
<requestFiltering removeServerHeader ="true" />
</security>
More details on how to remove all unwanted/unnecessary headers can be found here.
Please note that this hides server header from the "application", as do all the other approaches. If you e.g. reach some default page or an error page generated by the IIS itself or ASP.NET outside your application these rules won't apply. So ideally they should be on the root level in IIS and that sill may leave some error responses to the IIS itself.
Note there is a bug in IIS 10 that makes it sometimes show the header even with the modified config prior to 2019.1C. It should be fixed by now, but IIS/Windows has to be updated.
Add the below code in Global.asax.cs:
protected void Application_PreSendRequestHeaders()
{
// Remove the default Server header
Response.Headers.Remove("Server");
// Optionally, add your own Server header
Response.AddHeader("Server", "My-App/1.0");
}
This has been tested to work under IIS 8.5 and 10.0.
Unfortunately most of the recommendations you will find online for removing the "Server" header in IIS will not work for IIS 8.0 and 8.5. I have found the only working option, and in my opinion, also the best, is to use an IIS Native-Code module.
Native-Code modules differ from the more common Managed modules, as they are written using the win32 APIs rather than ASP.NET. This means that they work for all requests (including static pages and images) rather than just requests that past though the ASP.NET pipeline. Using a Native-Code module, it is possible to remove unwanted headers at the very end of the request, meaning that you can remove headers (including the "Server" header) regardless of where they have been set.
Binaries and source code of an example Native-Code module for removing headers in IIS 7.0 to 8.5 are available in the following article.
https://www.dionach.com/en-au/blog/easily-remove-unwanted-http-headers-in-iis-7-0-to-8-5/
Just use clear tag in custom headers segment in web.config:
<system.webServer>
<httpProtocol>
<customHeaders>
<clear />
<add name="X-Custom-Name1" value="MyCustomValue1" />
<add name="X-Custom-Name2" value="MyCustomValue2" />
</customHeaders>
</httpProtocol>
</system.webServer>
For dynamic headers, You can use this code in Global.ascx:
protected void Application_PreSendRequestHeaders()
{
Response.Headers.Remove("Server");
Response.AddHeader("Sample1", "Value1");
}
This is dead simple. Just create a custom module:
public class HeaderStripModule : IHttpModule
{
public void Init(HttpApplication application)
{
application.PreSendRequestHeaders += (sender, args) => HttpContext.Current.Response.Headers.Remove("Server");
}
public void Dispose(){}
}
And then register in web.config or applicationHost.config if you want machine wide implementation.
<system.webServer>
<modules>
<add name="HeaderStripModule" type="MyNamespace.HeaderStripModule" />
</modules>
</system.webServer>
URLScan has been discontinued starting from IIS 7.5, since its functionalities are supposed to be available through "request filtering" option (feature added in IIS 7.5).
But the URLScan's 'Remove server header' option does not look like having any equivalent in "request filtering".
As said on this answer and this answer to you question, you can emptied the Server with URLRewrite instead, which remains available on IIS 8/8.5 (with some update required for having its UI in IIS administration console).
It turns out, looking at this blog, that URLScan can still be installed on IIS 8/8.5, if lack of official support is not an issue.
I have not tested myself. Here are the steps:
Install IIS 6 Metabase compatibility (if not already there)
Install Isapi Filters (if not already there)
Install URLScan (from download-able installer, not from web platform installer)
Configure URLScan through its ini file (by default in C:\Windows\System32\inetsrv\urlscan)
Maybe some iisreset or even a reboot should be done. URLScan should be visible in IIS among Isapi filters
In IIS Manager, at the server level, go to the Features view. Click on HTTP Response Headers. You can add/remove headers there. You can also manage the response headers at the site level as well.

How to remove WebApplication on uninstall?

I install WCF service to IIS.
Installer creates Virtual dir and convert it to web application. Unintallation removes all but Web application name remains under IIS site. How to remove it? There is the code
<iis:WebVirtualDir Id="VDir"
Alias="[WEB_APP_NAME]"
Directory="INSTALLDIR"
WebSite="TheWebSite" >
<!--Turn the Virtual Directory into a web application.-->
<iis:WebApplication Id="TestWebApplication"
Name="[WEB_APP_NAME]"
WebAppPool="TheAppPool"/>
</iis:WebVirtualDir>
<iis:WebAppPool Id="TheAppPool" Name="[APP_POOL_NAME]"/>
Also, Web site code is outside of component to prevent removing defaultwebsite:
<iis:WebSite Id='TheWebSite' Description='[WEBSITE_NAME]' Directory='INSTALLDIR'>
<iis:WebAddress Id="AllUnassigned" IP="*" Port="80"/>
</iis:WebSite>
Please check whether SKIPCONFIGUREIIS property was not set. If not (property was set) application will not be deleted

Asp.net application error running with Sitecore 6.4.1

I have Sitecore as site root (which is running ok) and under it I need to have a bunch of asp.net applications running.
So far, created a virtual directory for the child application, turned it into an app. But as soon as I browse the child app it comes with this error message.
Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: CS0246: The type or namespace name 'Sitecore' could not be found (are you missing a using directive or an assembly reference?)
Source Error:
Line 3264: </providers>
Line 3265: </roleManager>
Line 3266: <profile defaultProvider="sql" enabled="true" inherits="Sitecore.Security.UserProfile, Sitecore.Kernel">
Line 3267: <providers>
Line 3268: <clear/>
It seems that the child asp.net app is inheriting Sitecore settings which are coming from Sitecore web.config.
Any ideas?
This should be possible. You'll have to author a web.config for that non-Sitecore application in virtual directory, and overwrite the sections under <system.web> and <system.webserver> which reference Sitecore classes. This includes:
httpModules / httpHandlers (for these you should "remove all" and add those of that web app)
security section (put the default ASP.NET provider classes back)
in Sitecore main web.config add the path of this web app to IgnoreUrlPrefixes setting to let Sitecore know it should not handle requests to those
It might be something else, but you should get the general idea.
This answer is similar to Yan, but is different enough for a separate answer. Hope it helps.
Go into IIS and select the Child Application. Select Modules. Remove all the Sitecore related modules that are present. Don't worry, the parent Sitecore app will still retain these modules.
When you do this, you are actually changing the child app web.config, so you will see the elements removed in the web.config file like so.
<remove name="SitecoreConfigWatcher" />
<remove name="SitecoreHttpModule" />
You also may have to clear out some other inherited settings.
<profile enabled="false"><providers><clear/></providers></profile>
<roleManager enabled="false"><providers><clear /></providers></roleManager>

Resources