My requirement is how can hide response Header on bad Request 400 in Asp.net i was trying solve the problems.i will try add some code in web.config file as well as global.asax file but it is not working here i am attach a image for better understanding.can u figure out this problmes.
<system.webServer>
<rewrite>
<outboundRules>
<rule name="Remove RESPONSE_Server" >
<match serverVariable="RESPONSE_Server" pattern=".+" />
<action type="Rewrite" value="Company name" />
</rule>
</outboundRules>
</rewrite>
</system.webServer>
protected void Application_PreSendRequestHeaders()
{
Response.Headers.Remove("Server");
Response.Headers.Remove("Server");
Response.Headers.Remove("X-AspNet-Version");
Response.Headers.Remove("X-AspNetMvc-Version");
}
Related
I enabled Html5 mode in angular for my project witch convert my URl from
A: qwe.com/#/products
to
B: qwe.com/products
But the problem is in this case if user trying to directly go to B, server (web api) catch the Url and return not found error so I need a way to catch all not found in server add a # sign to that and redirect to new Url but how should I do it?
Update:
Thanks to #Travis Collins
In Global.asax
private const string ROOT_DOCUMENT = "/index.html";
protected void Application_BeginRequest( Object sender, EventArgs e )
{
string url = Request.Url.LocalPath;
if ( !System.IO.File.Exists( Context.Server.MapPath( url ) ) )
Context.RewritePath( ROOT_DOCUMENT );
}
You need to do the rewrite on your server end for this. This will make the web server still serve your index.html file even when a request comes in for /products or anything else. In IIS for example, you would do this in web.config:
<system.webServer>
<rewrite>
<rules>
<rule name="Main Rule" stopProcessing="true">
<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="/" />
</rule>
</rules>
</rewrite>
</system.webServer>
Lots of other servers are explained here:
https://github.com/angular-ui/ui-router/wiki/Frequently-Asked-Questions#how-to-configure-your-server-to-work-with-html5mode
I’m using URL Rewrite / ARR as reverse proxy to simulate a Wordpress installation in an IIS subdirectory which is actually running on a remote Apache.
It is working better than I’d expected, but there is one annoying problem left: When a user posts a comment it is correctly redirected and saved at the wp side. However, the following redirect doesn’t get rewritten correctly:
I’m getting e.g. http://domain.tld/2014/01/11/posttitle/#comment-6 instead of http://domain.tld/blog/2014/01/11/posttitle/#comment-6.
As I said before, all other relevant links/images/stylesheets are working as expected and are rewritten to domain.tld/blog/<path>.
The last operation on Wordpress side seems to be (in wp-comments-post.php):
$location = apply_filters( 'comment_post_redirect', $location, $comment );
wp_safe_redirect( $location );
Here are my rewrite rules:
<rewrite>
<rules>
<rule name="RewriteRemoteAddr">
<match url="(.*)" />
<conditions>
<add input="{HTTP_X_FORWARDED_FOR}" pattern="([_0-9a-zA-Z]+)" />
</conditions>
<serverVariables>
<set name="{REMOTE_ADDR}" value="{HTTP_X_FORWARDED_FOR}" />
</serverVariables>
<action type="None" />
</rule>
<rule name="ReverseProxyInboundRule1" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{CACHE_URL}" pattern="^(https?)://" />
</conditions>
<action type="Rewrite" url="{C:1}://blog.domain.tld/{R:1}" />
</rule>
</rules>
<outboundRules>
<rule name="ReverseProxyOutboundRule1" preCondition="ResponseIsHtml1">
<match filterByTags="A, Form, Img" pattern="^http(s)?://blog.domain.tld/(.*)" />
<action type="Rewrite" value="http{R:1}://domain.tld/blog/{R:2}" />
</rule>
<preConditions>
<preCondition name="ResponseIsHtml1">
<add input="{RESPONSE_CONTENT_TYPE}" pattern="^text/html" />
</preCondition>
</preConditions>
</outboundRules>
</rewrite>
System:
IIS 8.5, URL Rewrite 2, ARR 3
Wordpress 3.8
EDIT W3SVC9 log entries:
2014-01-11 19:12:14 W3SVC9 ares 444.444.444.444 POST /blog/wp-comments-post.php X-ARR-CACHE-HIT=0&X-ARR-LOG-ID=d6339e31-547d-4f25-b1cc-5ebe2b485a1d 443 - 333.333.333.333 HTTP/1.1 Mozilla/5.0+(Windows+NT+6.3;+WOW64;+rv:26.0)+Gecko/20100101+Firefox/26.0 comment_author_b9276ad9dc2bc4f28d3a0f251eafa31e=tester;+comment_author_email_b9276ad9dc2bc4f28d3a0f251eafa31e=test%40example.com;+wordpress_test_cookie=WP+Cookie+check https://domain.tld/blog/2013/12/27/posttitle/ blog.domain.tld 302 0 0 906 1283 156
2014-01-11 19:12:14 W3SVC9 ares 444.444.444.444 GET /2013/12/27/posttitle/ - 443 - 333.333.333.333 HTTP/1.1 Mozilla/5.0+(Windows+NT+6.3;+WOW64;+rv:26.0)+Gecko/20100101+Firefox/26.0 comment_author_b9276ad9dc2bc4f28d3a0f251eafa31e=tester;+comment_author_email_b9276ad9dc2bc4f28d3a0f251eafa31e=test%40example.com;+wordpress_test_cookie=WP+Cookie+check https://domain.tld/blog/2013/12/27/posttitle/ domain.tld 404 0 0 6282 926 171
Thanks!
I have the following code in my web.config
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="IP Correction">
<match url="(.*)" />
<serverVariables>
<set name="REMOTE_ADDR" value="{HTTP_X-Forwarded-For}"/>
</serverVariables>
<action type="None" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
This works perfectly on the root of my site, however, the rule isn't being triggered in any of the sub folders.
I figured this out. The problem was in this line of code
<action type="None" />
You have to specify the rewrite action
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="IP Correction">
<match url="(.*)" ignoreCase="true" />
<serverVariables>
<set name="REMOTE_ADDR" value="{HTTP_X-Forwarded-For}" replace="true"/>
</serverVariables>
<action type="Rewrite" url="{R:0}" appendQueryString="true" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
I faced a similar issue and created an IHttpModule to address it, which you can find here. URL Rewrite seems to have a bug where it won't execute on default document requests. The module doesn't have that issue. To implement it on your site, you'd add it to the <modules> section of your web.config, or if you want it to run server-wide, to your applicationHost.config.
The relevant bit of code is that you're hooking into HttpApplication's BeginRequest event, and running:
void OnBeginRequest(object sender, EventArgs e)
{
HttpApplication app = (HttpApplication)sender;
string headervalue = app.Context.Request.Headers["X-Forwarded-For"];
if (headervalue != null)
{
Match m = REGEX_FIRST_IP.Match(headervalue);
if (m.Success)
{
app.Context.Request.ServerVariables["REMOTE_ADDR"] = m.Groups[1].Value;
app.Context.Request.ServerVariables["REMOTE_HOST"] = m.Groups[1].Value;
}
}
}
The Regex is ^\s*(\d+\.\d+\.\d+\.\d+). Full code at the gist.
If you compiled this code into a class library called HttpModules and put it in your GAC, you could then add this to your <modules> section, something like:
<add name="ClientIP" type="YourLibrary.ClientIP, YourLibrary, Version=1.0.0.0, Culture=neutral, PublicKeyToken=00DEADBEEF00" />
Just like in a title. How to redirect whole domain for example: http://testdomain.com.au/ to https://testdomain.com.au/ Can i do it in IIRF file ? If yes how this should look like ? How to bind IIRF file to site ?
You can do this via an IIS Rewrite module:
http://www.iis.net/downloads/microsoft/url-rewrite
http://www.iis-aid.com/articles/how_to_guides/redirect_http_to_https_iis_7
<rule name="HTTP to HTTPS redirect" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="off" ignoreCase="true" />
</conditions>
<action type="Redirect" redirectType="Found" url="https://{HTTP_HOST}/{R:1}" />
</rule>
Or you can redirect via the Global.asax file:
protected void Application_BeginRequest(Object sender, EventArgs e)
{
if ( !Request.IsSecureConnection)
{
string path = string.Format("https{0}", Request.Url.AbsoluteUri.Substring(4));
Response.Redirect(path);
}
}
http://forums.asp.net/t/1340392.aspx
I have started using ASP.NET Routing for my site. I have been registering routes via the Application_Start() in my Global.asax file.
i.e.
routes.MapPageRoute("ROUTE-ABOUT", "about", "~/About.aspx");
routes.MapPageRoute("ROUTE-CONTACT", "contact", "~/Contact.aspx");
//etc...
This is working perfectly for the About and Contact pages.
What I Want:
My home page is Home.aspx and what I wanted to do is rewrite anyone that visits
http://localhost/mysite.com/Home.aspx
to
http://localhost/mysite.com/Home
What I've Tried
I have my site running in my local IIS v7.5 on my machine (full
administrator privileges).
I have added the following to my Web.config
Web.config
<rewrite>
<rules>
<rule name="HOMETOSEO" stopProcessing="true">
<match url="Home\.aspx" />
<action type="Redirect" url="home" appendQueryString="false" />
</rule>
</rules>
</rewrite>
Thanks in advance
After hours of trying to get this to work I eventually managed to get it working using the following entry in the Web.config and Application_Start() of the Global.asax file:
Web.config
<rewrite>
<rules>
<rule name="default" enabled="true" patternSyntax="ECMAScript" stopProcessing="false">
<match url="(.*)Home\.aspx" ignoreCase="true" />
<action type="Redirect" url="home" appendQueryString="false" />
</rule>
<rule name="lower" enabled="true" patternSyntax="ECMAScript" stopProcessing="true">
<match url="[A-Z]" ignoreCase="false" />
<action type="Redirect" url="{ToLower:{URL}}" />
</rule>
</rules>
</rewrite>
Global.asax
protected void Application_Start(object sender, EventArgs e)
{
//...
BuildStaticRoutes(RouteTable.Routes);
//...
}
public void BuildStaticRoutes(RouteCollection routes)
{
//...
routes.MapPageRoute("ROUTE-HOME", "home", "~/Home.aspx");
//...
}
If you are using IIS v7.5 you can add this in web.config
<system.webServer>
<rewrite>
<rules>
<rule name="HOMETOSEO" stopProcessing="true">
<match url="^Home" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="Home.aspx" />
</rule>
</rules>
</rewrite>
</system.webServer>
When you type http://mysite.com/Home, it will display http://mysite.com/Home.aspx. Is that what you are after or the other way around?
You can do it using a custom route by inheriting from RouteBase - so in your case it would look something like this
public class HomeRoute : RouteBase
{
public override RouteData GetRouteData(HttpContextBase httpContext)
{
if (httpContext.Request.Url.ToString().ToLower().Contains("home.aspx"))
{
httpContext.Response.Status = "301 Moved Permanently"; //Optional 301 redirect
httpContext.Response.RedirectLocation = "Home";
httpContext.Response.End();
}
return null;
}
public override VirtualPathData GetVirtualPath(RequestContext requestContext, RouteValueDictionary values)
{
return null;
}
}
And then in you register routes you would have
routes.Add("HomeUrl", new HomeRoute());
So that any request to /Home.aspx would automatically redirect to /Home - obviously with a bit of extra work you could make this a bit more generic for any .aspx request.