0

Background: I work with ASPX files and webforms (as my day job) but have never really worked with Razor (.cshtml).

I am trying to create a website that logs into Steam using Owin.Security.Providers.

When i do Install-Package Install-Package Owin.Security.Providers and implement the API from https://steamcommunity.com/dev/apikey, I noticed that the corresponding button is implemented in Razor as shown below.

 using (Html.BeginForm("ExternalLogin", "Account", new { ReturnUrl = Model.ReturnUrl })) {
            @Html.AntiForgeryToken()
            <div id="socialLoginList">
                <p>
                    @foreach (AuthenticationDescription p in loginProviders) {
                        <button type="submit" class="btn btn-default" id="@p.AuthenticationType" name="provider" value="@p.AuthenticationType" title="Log in using your @p.Caption account">@p.AuthenticationType</button>
                    }
                </p>
            </div>

Questions:

Is there a way to get the same function above in an ASPX page instead of in a CSHTML page?

Is it the following code that gives the button the link for the login?

using (Html.BeginForm("ExternalLogin", "Account", new { ReturnUrl = Model.ReturnUrl })) {
Sabuncu
  • 5,095
  • 5
  • 55
  • 89
bobby
  • 183
  • 9

1 Answers1

1

Razor can be triviaally converted to ASPX syntax.

If you're using ASPX syntax within an ASP.NET MVC context you can use the Html helpers, just like in Razor:

<% using (Html.BeginForm("ExternalLogin", "Account", new { ReturnUrl = Model.ReturnUrl })) { %>
    <%= Html.AntiForgeryToken %>
    <div id="socialLoginList">
        <p>
        <% foreach( AuthenticationDescription p in loginProviders ) { %>
            <button type="submit" class="btn btn-default" id="<%= p.AuthenticationType %>" name="provider" value="<%= p.AuthenticationType %>" title="Log in using your <%= p.Caption %> account"><%= p.AuthenticationType %></button>
            <% } // foreach %>
        </p>
    </div>
<% } // using %>

(NOTE: Use <%: instead of <%= for output that should be HTML-encoded). I don't know what strings in your output should be encoded or not.

If you're using it in a non-MVC context then you'll need to replace the Html helpers with literal HTML. Do not use WebControls (like <asp:Form>) because you lose control over the markup:

Dai
  • 141,631
  • 28
  • 261
  • 374