1

I need to redirect from htttp://metroyapi.com.tr or/and "http://www.metroyapi.com.tr" to https://www.metroyapi.com.tr.

I already tried the following methods but none of them worked.

At Startup:

app.Use(async (context, next) =>
        {
            if (context.Request.IsSecure) {
                await next();
            } else {
                var withHttps = Uri.UriSchemeHttps + Uri.SchemeDelimiter + context.Request.Uri.GetComponents(UriComponents.AbsoluteUri & ~UriComponents.Scheme, UriFormat.SafeUnescaped);
                context.Response.Redirect(withHttps);
            }
        });

At Global.asax:

if (!Context.Request.IsSecureConnection)
            Response.Redirect(Context.Request.Url.ToString().Replace("http:", "https:"));

and

if (!HttpContext.Current.Request.IsSecureConnection) {
            Response.Redirect("https://" + Request.ServerVariables["HTTP_HOST"]
                                         + HttpContext.Current.Request.RawUrl);
        }

At FilterConfig:

filters.Add(new RequireHttpsAttribute());

and bunch of web.config solution.

None of them worked I still get 404 error.

Any suggestions?

Help is much precited!

Metro Diji
  • 19
  • 4
  • Did you look at this article? http://tech.trailmax.info/2014/02/implemnting-https-everywhere-in-asp-net-mvc-application/ – Wouter van Vegchel Jan 19 '17 at 10:06
  • I am going to do that. Thank you! – Metro Diji Jan 19 '17 at 10:13
  • I am sorry but i guess there is a misunderstanding and it is my fault. The redirect i like to do is as follows. I need to redirect from htttp://metroyapi.com.tr or http://www.metroyapi.com.tr to https://www.metroyapi.com.tr – Metro Diji Jan 19 '17 at 10:31

0 Answers0