I need to read web.config settings. I have added following settings to web.config
<handlers>
<remove name="WebServiceHandlerFactory-Integrated" />
<add name="PageHandlerFactory-Integrated-HTML" path="*.html"
verb="GET,HEAD,POST,DEBUG" type="System.Web.UI.PageHandlerFactory"
resourceType="Unspecified" preCondition="integratedMode,runtimeVersionv4.0" />
and
<buildProviders>
<add extension=".html"
type="System.Web.Compilation.PageBuildProvider" />
</buildProviders>
It works fine for all html pages that have.html in extension.
But for pages urls like http://testsite.com/aaa which displays 404 html page in response , the configuration is not read.
What can be done to include pages without extensions.
I was facing this issue for error pages.
After changing settings for httpErrors in web.config, things worked for me.
I changed
<httpErrors errorMode="Custom" existingResponse="Replace">
<remove statusCode="404" />
<error statusCode="404" path="holdingClientError.html" responseMode="File" />
To
<httpErrors errorMode="Custom" existingResponse="Replace">
<remove statusCode="404" />
<error statusCode="404" path="/holdingClientError.html" responseMode="ExecuteURL" />
Related
I have a little problem with the web.config file of my angular universal project. My web.config file is like this;
<configuration>
<system.webServer>
<!-- indicates that the server.js file is a node.js application
to be handled by the iisnode module -->
<handlers>
<add name="iisnode" path="main.js" verb="*" modules="iisnode" />
</handlers>
<rewrite>
<rules>
<rule name="sendToNode">
<match url="/*" />
<action type="Rewrite" url="main.js" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
We are trying to add a www redirecting when there is no www written into link and a https redirecting when there is no https written in the url. But we couldnt manage to do this.
Should I need to do something from the Angular for this?
How can we add those two redirectings into our angular universal web config?
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.web>
<httpRuntime enableVersionHeader="false" />
</system.web>
<system.webServer>
<httpProtocol>
<customHeaders>
<add name="Strict-Transport-Security" value="max-age=31536000"/>
<add name="X-Content-Type-Options" value="nosniff" />
<add name="X-Frame-Options" value="DENY" />
<add name="X-XSS-Protection" value="1; mode=block" />
<remove name="X-Powered-By" />
</customHeaders>
</httpProtocol>
<webSocket enabled="false" />
<handlers>
<!-- Indicates that the main.js file is a node.js site to be handled by the iisnode module -->
<add name="iisnode" path="main.js" verb="*" modules="iisnode"/>
</handlers>
<rewrite>
<rules>
<rule name="HTTP to HTTPS redirect" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="off" ignoreCase="true" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="Permanent"/>
</rule>
<!-- Do not interfere with requests for node-inspector debugging -->
<rule name="NodeInspector" patternSyntax="ECMAScript" stopProcessing="true">
<match url="^main.js\/debug[\/]?" />
</rule>
<!-- All other URLs are mapped to the node.js site entry point -->
<rule name="DynamicContent">
<match url="^(?!.*login).*$"></match>
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true"/>
</conditions>
<action type="Rewrite" url="main.js"/>
</rule>
</rules>
<outboundRules>
<rule name="Add Strict-Transport-Security when HTTPS" enabled="true">
<match serverVariable="RESPONSE_Strict_Transport_Security" pattern=".*" />
<conditions>
<add input="{HTTPS}" pattern="on" ignoreCase="true" />
</conditions>
<action type="Rewrite" value="max-age=31536000" />
</rule>
</outboundRules>
</rewrite>
<!-- 'bin' directory has no special meaning in node.js and apps can be placed in it -->
<security>
<requestFiltering>
<hiddenSegments>
<remove segment="bin"/>
</hiddenSegments>
</requestFiltering>
</security>
<!-- Make sure error responses are left untouched -->
<httpErrors existingResponse="PassThrough" />
<!-- Restart the server if any of these files change -->
<iisnode watchedFiles="web.config;*.js;browser/*.*" />
</system.webServer>
</configuration>
Am making a Plugin architecture application using Asp.Net MVC 5 so I created a class library project that will contains some controllers and some embedded Razor views. everything works fine i made some references to the followingDlls `System.Web.Mvc/System.Web.Optimazations/System.Web.Razor/System.Web.WebPages/System.Web.WebPages.Razor/System.Web.helpers.
I added a web.config file and this is what it contains :
<?xml version="1.0"?>
<configuration>
<configSections>
<sectionGroup name="system.web.webPages.razor" type="System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
<section name="host" type="System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
<section name="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
</sectionGroup>
</configSections>
<system.web.webPages.razor>
<host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<pages pageBaseType="System.Web.Mvc.WebViewPage">
<namespaces>
<add namespace="System.Web.Mvc" />
<add namespace="System.Web.Mvc.Ajax" />
<add namespace="System.Web.Mvc.Html" />
<add namespace="System.Web.Optimization"/>
<add namespace="System.Web.Routing" />
<add namespace="Plugin_1" />
</namespaces>
</pages>
</system.web.webPages.razor>
<appSettings>
<add key="webpages:Enabled" value="false" />
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.5.2" >
</compilation>
<httpRuntime targetFramework="4.5.2" />
<pages>
<namespaces>
<add namespace="System.Web.Mvc" />
<add namespace="System.Web.Mvc.Ajax" />
<add namespace="System.Web.Mvc.Html" />
<add namespace="System.Web.Optimization"/>
<add namespace="System.Web.Routing" />
<add namespace="Plugin_1" />
<add namespace="Kendo.Mvc.UI"/>
</namespaces>
</pages>
<httpModules>
<add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web" />
</httpModules>
</system.web>
<system.webServer>
<handlers>
<remove name="BlockViewHandler"/>
<add name="BlockViewHandler" path="*" verb="*" preCondition="integratedMode" type="System.Web.HttpNotFoundHandler" />
</handlers>
</system.webServer>
</configuration>
I can use the #model keyword etc but i cannot use html helper like "#Html.ActionLink() etc , #Html is not recognized to vs 2015 !!
Can any one help me please i've seen some similar questions here on StackOF but it doesnt help. and Thank you.
To make Intellisense show the ASP.NET MVC specific properties you need to change the output path of your class library to bin:
Right click project -> Properties -> Build -> change Output path to "bin/"
Now if you open a Razor file in your class library you will get Intellisense for things like Html.ActionLink.
you need to add razor reference into project and web config
I read that .htaccess doesn't work on windows server like godaddy. So to hide or remove extensions like .php and .html on URL, you can accomplish this by creating a web.config file with the following code:
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="RewriteHTML">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions> <action type="Rewrite" url="{R:1}.html" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
I tried to make web.config file and save it where index.php is with that code but nothing happened.. I tested it with the like this
<ul>
<li>
Attack on Titan Episode 3
</li>
</ul> with a href of "attackontitan-3"
I want url to be http://mysite/watching/attack%20on%20titan/attackontitan-3 not http://mysite/watching/attack%20on%20titan/attackontitan-3.php
Use rewrite to add the extension, like this:
<rule name="rewritephp">
<!--Removes the .aspx extension for all pages.-->
<match url="(.*)" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="{R:1}.php" />
</rule>
Or This tutorial does a great job at explaining what you need to do with IIS.
http://atlantawebsites.blogspot.com/2010/06/vanity-urls-with-godaddy-hosting-using.html
You need to add a Rewrite and Redirect rules. The following will redirect and rewrite page.php to just page. If you want to do the same for html, just add those rules.
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<!-- Remove the existing rules just incase we already defined them -->
<remove name="RedirectPhpExtensions" />
<remove name="RewritePhpExtensions" />
<!-- Add a rule to redirect x.php pages to just x -->
<rule name="RedirectPhpExtensions" enabled="true" stopProcessing="true">
<match url="(.*)\.php$" />
<action type="Redirect" url="{R:1}" redirectType="Permanent" />
</rule>
<!-- Add a rule to rewrite the x pages to x.php behind the scene -->
<rule name="RewritePhpExtensions" enabled="true" stopProcessing="true">
<match url="(.*)" negate="false" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="{R:1}.php" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
Place this web.config in the root directory of your domain.
Then you need to restart the Application Pool on godaddy's site:
Web Hosting > Manage > IIS Management > Recycle App Pool button
I am running a Asp.Net Host (ServiceStack.Host.AspNet 4.0.30.0) - ServiceStack 4.0.30.0 project with Razor.
.Net Framework Target: 4.5.1
The project compiles fine, but I am not getting any intellisense in my Razor Views using Visual Studio 2013 with Update 2.
Any ideas on how to get intellisense to work in the ServiceStack Razor views?
My machine has MVC 4 and 5 installed as well.
Here is also a copy of my web.config...
<?xml version="1.0" encoding="utf-8"?>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<configSections>
<sectionGroup name="system.web.webPages.razor" type="System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor">
<section name="host" type="System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor" requirePermission="false" />
<section name="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor" requirePermission="false" />
</sectionGroup>
</configSections>
<!--
For a description of web.config changes see http://go.microsoft.com/fwlink/?LinkId=235367.
The following attributes can be set on the <httpRuntime> tag.
<system.Web>
<httpRuntime targetFramework="4.5.1" />
</system.Web>
-->
<system.web>
<httpRuntime />
<compilation targetFramework="4.5.1" debug="true">
<buildProviders>
<add extension=".cshtml" type="ServiceStack.Razor.CSharpRazorBuildProvider, ServiceStack.Razor" />
</buildProviders></compilation>
<pages controlRenderingCompatibilityVersion="4.0" />
<httpHandlers>
<add path="*" type="ServiceStack.HttpHandlerFactory, ServiceStack" verb="*" />
</httpHandlers></system.web>
<system.web.webPages.razor>
<pages pageBaseType="ServiceStack.Razor.ViewPage">
<namespaces>
<add namespace="windows_consumer81_demo.Models" />
<add namespace="windows_consumer81_demo.Models.Scenario" />
<add namespace="windows_consumer81_demo.Localization" />
<add namespace="System" />
<add namespace="ServiceStack" />
<add namespace="ServiceStack.Html" />
<add namespace="ServiceStack.Razor" />
<add namespace="ServiceStack.Text" />
<add namespace="ServiceStack.OrmLite" />
<add namespace="windows_consumer81_demo" />
</namespaces>
</pages>
<host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc" />
</system.web.webPages.razor>
<appSettings>
<add key="DebugMode" value="true" />
<add key="unsupportedRedirect" value="unsupported.html" />
<add key="vs:EnableBrowserLink" value="false" />
<add key="webPages:Enabled" value="false" /></appSettings>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" />
<validation validateIntegratedModeConfiguration="false" />
<handlers>
<add path="*" name="ServiceStack.Factory" type="ServiceStack.HttpHandlerFactory, ServiceStack" verb="*" preCondition="integratedMode" resourceType="Unspecified" allowPathInfo="true" />
</handlers>
</system.webServer>
</configuration>
I guess the way it's supposed to work is that all the namespaces you add in web.config should have IntelliSense:
<system.web.webPages.razor>
<pages pageBaseType="ServiceStack.Razor.ViewPage">
<namespaces>
<add namespace="YourNameSpaceHere" />
<add namespace="SomeServiceStackNameSpace" />
. . .
Then in the .cshtml file you'd add:
#inherits ViewPage<YourModelClassName>
Unfortunately this doesn't always work. It compiles, but you don't get IntelliSense.
However there is a fix:
In your .cshtml file just type out the full namespace:
#inherits ServiceStack.Razor.ViewPage<Full.Namespace.Of.Your.Model.Class>
If you're using other classes, just add:
#using MyServer.ServiceInterface;
#using MyServer.ServiceModel;
Another trick I recommend is to strongly type your #Model object. Right there at the top, after the #Inherits ViewPage<...> stuff add:
#{
Your.Class.Name TypedModel = Model;
}
Feel free to rename TypedModel to something better.
I am building a new site with custom error pages. I have setup my web.config, and have all of my pages setup.
When I run locally, and force errors (page not found is the easy one), it all works well. But when I publish to my Windows Server 2008 R2 production server, and enter a bad page, it still takes me to the default IIS7 error page.
Here is a sample from my web.config (and my pages are all there):
<?xml version="1.0"?>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0"/>
<customErrors mode="On" defaultRedirect="~/ErrorGeneral">
<error statusCode="400" redirect="~/ErrorBadRequest" />
<error statusCode="401" redirect="~/ErrorUnathorized" />
<error statusCode="402" redirect="~/ErrorPaymentRequired" />
<error statusCode="403" redirect="~/ErrorForbidden" />
<error statusCode="404" redirect="~/ErrorItemNotFound" />
<error statusCode="405" redirect="~/ErrorMethodNotAllowed" />
<error statusCode="406" redirect="~/ErrorNotAcceptable" />
<error statusCode="412" redirect="~/ErrorPreconditionFailed" />
<error statusCode="500" redirect="~/ErrorInternalServerError" />
<error statusCode="501" redirect="~/ErrorNotImplemented" />
<error statusCode="502" redirect="~/ErrorBadGateway" />
</customErrors>
</system.web>
</configuration>
Am I doing something simple incorrectly? Is it a difference with Windows Server 2008 R2?
EDIT: I found the issue, which is additional information in the web.config file, to look like this:
<?xml version="1.0" encoding="UTF-8"?>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
<customErrors mode="On" defaultRedirect="~/ErrorGeneral">
<error statusCode="400" redirect="~/ErrorBadRequest" />
<error statusCode="401" redirect="~/ErrorUnathorized" />
<error statusCode="402" redirect="~/ErrorPaymentRequired" />
<error statusCode="403" redirect="~/ErrorForbidden" />
<error statusCode="404" redirect="~/ErrorItemNotFound" />
<error statusCode="405" redirect="~/ErrorMethodNotAllowed" />
<error statusCode="406" redirect="~/ErrorNotAcceptable" />
<error statusCode="412" redirect="~/ErrorPreconditionFailed" />
<error statusCode="500" redirect="~/ErrorInternalServerError" />
<error statusCode="501" redirect="~/ErrorNotImplemented" />
<error statusCode="502" redirect="~/ErrorBadGateway" />
</customErrors>
</system.web>
<system.webServer>
<httpErrors>
<remove statusCode="502" subStatusCode="-1" />
<remove statusCode="501" subStatusCode="-1" />
<remove statusCode="500" subStatusCode="-1" />
<remove statusCode="412" subStatusCode="-1" />
<remove statusCode="406" subStatusCode="-1" />
<remove statusCode="405" subStatusCode="-1" />
<remove statusCode="403" subStatusCode="-1" />
<remove statusCode="401" subStatusCode="-1" />
<remove statusCode="404" subStatusCode="-1" />
<error statusCode="404" prefixLanguageFilePath="" path="/Pages/ErrorItemNotFound.aspx" responseMode="ExecuteURL" />
<error statusCode="401" prefixLanguageFilePath="" path="/Pages/ErrorUnauthorized.aspx" responseMode="ExecuteURL" />
<error statusCode="403" prefixLanguageFilePath="" path="/Pages/ErrorForbidden.aspx" responseMode="ExecuteURL" />
<error statusCode="405" prefixLanguageFilePath="" path="/Pages/ErrorMethodNotAllowed.aspx" responseMode="ExecuteURL" />
<error statusCode="406" prefixLanguageFilePath="" path="/Pages/ErrorNotAcceptable.aspx" responseMode="ExecuteURL" />
<error statusCode="412" prefixLanguageFilePath="" path="/Pages/ErrorPreconditionFailed.aspx" responseMode="ExecuteURL" />
<error statusCode="500" prefixLanguageFilePath="" path="/Pages/ErrorInternalServerError.aspx" responseMode="ExecuteURL" />
<error statusCode="501" prefixLanguageFilePath="" path="/Pages/ErrorNotImplemented.aspx" responseMode="ExecuteURL" />
<error statusCode="502" prefixLanguageFilePath="" path="/Pages/ErrorBadGateway.aspx" responseMode="ExecuteURL" />
</httpErrors>
</system.webServer>
</configuration>
By default IIS7 intercepts HTTP status codes such as 4xx and 5xx generated by applications further up the pipeline.
You can tell IIS to just pass through the existing response without replacing it with its own error page:
<configuration>
<system.webServer>
<httpErrors existingResponse="PassThrough" />
</system.webServer>
</configuration>
For more information see:
HTTP Errors <httpErrors>
Does this help?
I wonder if you also have to register the paths to the custom errors that way as well.