1

I have a web site that runs primarily in https. I have a couple of pages that have to interact with hardware that must run in http. I'm using an override of ActionLink to specify protocol of http. I see http as the link in the browser console.

@Html.ActionLink("Set Up WiFi", "setupWiFi", "Utility", "http", null, null, null, null)

The problem (maybe it's with IIS 8.5) is the link keeps coming up https.

2 Answers 2

1

You can't do something like this using the stock HtmlHelper extension methods, but you can use the same link-generation framework the HtmlHelper ActionLink extension method is using. Under the covers, ActionLink uses a static method named GenerateLink, which does allow you to supply a protocol name:

public static string GenerateLink(RequestContext requestContext, RouteCollection routeCollection, string linkText, string routeName, string actionName, string controllerName, string protocol, string hostName, string fragment, RouteValueDictionary routeValues, IDictionary<string, object> htmlAttributes)

So, using this method (which emits a string) coupled with the HtmlHelper class' ability to emit raw HTML using the Raw method, you can write your overridden links:

@Html.Raw(HtmlHelper.GenerateLink(
  ViewContext.RequestContext, 
  Html.RouteCollection, 
  "My Link Text Here", null, 
  "ActionNameHere", 
  "ControllerNameHere", 
  "http", 
  null, 
  null, 
  null, 
  null))
Sign up to request clarification or add additional context in comments.

Comments

0

I turns out a previous programmer had implemented a URL rewrite routine in Global.asax.cs file, in the Application_PreRequestHandlerExecute method. It was taking all URL's and rewriting them as https.

@Andy Hopper The original @Html.ActionLink("Set Up WiFi", "setupWiFi", "Utility", "http", null, null, null, null) produces a correct http:// link.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.